@@ -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