Skip to content

Commit 798ced0

Browse files
committed
fix(package): fixed the calculation of the strength (unit transform)
1 parent b70cb74 commit 798ced0

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

demo/src/app/home/home.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ <h1>@angular-material-extensions/password-strength</h1>
7979

8080
<!--@angular-material-extensions/password-strength's main component-->
8181
<mat-password-strength #passwordComponent
82+
[enableDigitRule]="false"
8283
(onStrengthChanged)="onStrengthChanged($event)"
8384
[password]="password.value">
8485
</mat-password-strength>

src/module/component/mat-password-strength/mat-password-strength.component.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,12 @@ export class MatPasswordStrengthComponent implements OnInit, OnChanges {
4646
containAtLeastOneDigit: boolean;
4747
containAtLeastOneSpecialChar: boolean;
4848

49-
passwordFormControl: AbstractControl;
49+
passwordFormControl: AbstractControl = new FormControl();
5050

5151
private _strength: number;
5252

5353
private _color: string;
5454

55-
56-
constructor() {
57-
this.setRulesAndValidators();
58-
}
59-
6055
ngOnInit(): void {
6156
this.setRulesAndValidators();
6257
}
@@ -149,16 +144,20 @@ export class MatPasswordStrengthComponent implements OnInit, OnChanges {
149144

150145
calculatePasswordStrength() {
151146
const requirements: Array<boolean> = [];
152-
const unit = 100 / 5;
147+
const unit = 100 / this.criteriaMap.size;
148+
149+
console.log('this.criteriaMap.size = ', this.criteriaMap.size);
150+
console.log('unit = ', unit);
153151

154152
requirements.push(
155-
this._containAtLeastEightChars(),
156-
this._containAtLeastOneLowerCaseLetter(),
157-
this._containAtLeastOneUpperCaseLetter(),
158-
this._containAtLeastOneDigit(),
159-
this._containAtLeastOneSpecialChar());
153+
this.enableLengthRule ? this._containAtLeastEightChars() : false,
154+
this.enableLowerCaseLetterRule ? this._containAtLeastOneLowerCaseLetter() : false,
155+
this.enableUpperCaseLetterRule ? this._containAtLeastOneUpperCaseLetter() : false,
156+
this.enableDigitRule ? this._containAtLeastOneDigit() : false,
157+
this.enableSpecialCharRule ? this._containAtLeastOneSpecialChar() : false);
160158

161159
this._strength = requirements.filter(v => v).length * unit;
160+
console.log('length = ', this._strength / unit);
162161
this.onStrengthChanged.emit(this.strength);
163162
}
164163

0 commit comments

Comments
 (0)