Skip to content

Commit

Permalink
fix(package): fixed the calculation of the strength (unit transform)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyNahas committed Aug 1, 2018
1 parent b70cb74 commit 798ced0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions demo/src/app/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ <h1>@angular-material-extensions/password-strength</h1>

<!--@angular-material-extensions/password-strength's main component-->
<mat-password-strength #passwordComponent
[enableDigitRule]="false"
(onStrengthChanged)="onStrengthChanged($event)"
[password]="password.value">
</mat-password-strength>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,12 @@ export class MatPasswordStrengthComponent implements OnInit, OnChanges {
containAtLeastOneDigit: boolean;
containAtLeastOneSpecialChar: boolean;

passwordFormControl: AbstractControl;
passwordFormControl: AbstractControl = new FormControl();

private _strength: number;

private _color: string;


constructor() {
this.setRulesAndValidators();
}

ngOnInit(): void {
this.setRulesAndValidators();
}
Expand Down Expand Up @@ -149,16 +144,20 @@ export class MatPasswordStrengthComponent implements OnInit, OnChanges {

calculatePasswordStrength() {
const requirements: Array<boolean> = [];
const unit = 100 / 5;
const unit = 100 / this.criteriaMap.size;

console.log('this.criteriaMap.size = ', this.criteriaMap.size);
console.log('unit = ', unit);

requirements.push(
this._containAtLeastEightChars(),
this._containAtLeastOneLowerCaseLetter(),
this._containAtLeastOneUpperCaseLetter(),
this._containAtLeastOneDigit(),
this._containAtLeastOneSpecialChar());
this.enableLengthRule ? this._containAtLeastEightChars() : false,
this.enableLowerCaseLetterRule ? this._containAtLeastOneLowerCaseLetter() : false,
this.enableUpperCaseLetterRule ? this._containAtLeastOneUpperCaseLetter() : false,
this.enableDigitRule ? this._containAtLeastOneDigit() : false,
this.enableSpecialCharRule ? this._containAtLeastOneSpecialChar() : false);

this._strength = requirements.filter(v => v).length * unit;
console.log('length = ', this._strength / unit);
this.onStrengthChanged.emit(this.strength);
}

Expand Down

0 comments on commit 798ced0

Please sign in to comment.