@@ -30,54 +30,45 @@ export function checkPasswordWithResult({
30
30
containsAlphabet = true ,
31
31
checkWithCommonPasswords = false ,
32
32
} : IParams ) : VerificationResult {
33
- if ( minLen != 0 ) {
34
- if ( password . length < minLen ) {
35
- return {
36
- isValid : false ,
37
- reason : `The password should contain at least ${ minLen } characters` ,
38
- } ;
39
- }
33
+ if ( minLen != 0 && password . length < minLen ) {
34
+ return {
35
+ isValid : false ,
36
+ reason : `The password should contain at least ${ minLen } characters` ,
37
+ } ;
40
38
}
41
- if ( maxLen != 0 ) {
42
- if ( password . length > maxLen ) {
43
- return {
44
- isValid : false ,
45
- reason : `The password should contain at most ${ maxLen } characters` ,
46
- } ;
47
- }
39
+ if ( maxLen != 0 && password . length > maxLen ) {
40
+ return {
41
+ isValid : false ,
42
+ reason : `The password should contain at most ${ maxLen } characters` ,
43
+ } ;
48
44
}
49
- if ( containsNum ) {
50
- if ( password . search ( / \d / ) == - 1 ) {
51
- return {
52
- isValid : false ,
53
- reason : "The password should contain at least one digit" ,
54
- } ;
55
- }
45
+ if ( containsNum && password . search ( / \d / ) == - 1 ) {
46
+ return {
47
+ isValid : false ,
48
+ reason : "The password should contain at least one digit" ,
49
+ } ;
56
50
}
57
- if ( containsSpecialChar ) {
58
- if ( password . search ( / [ ^ \w \s ] / ) == - 1 ) {
59
- return {
60
- isValid : false ,
61
- reason : "The password should contain at least one special character" ,
62
- } ;
63
- }
51
+ if ( containsSpecialChar && password . search ( / [ ^ \w \s ] / ) == - 1 ) {
52
+ return {
53
+ isValid : false ,
54
+ reason : "The password should contain at least one special character" ,
55
+ } ;
64
56
}
65
- if ( containsAlphabet ) {
66
- if ( password . search ( / [ A - Z a - z ] / ) == - 1 ) {
67
- return {
68
- isValid : false ,
69
- reason : "The password should contain at least one letter" ,
70
- } ;
71
- }
57
+ if ( containsAlphabet && password . search ( / [ A - Z a - z ] / ) == - 1 ) {
58
+ return {
59
+ isValid : false ,
60
+ reason : "The password should contain at least one letter" ,
61
+ } ;
72
62
}
73
63
74
- if ( checkWithCommonPasswords ) {
75
- if ( passwordList != undefined && passwordList . includes ( password ) ) {
76
- return {
77
- isValid : false ,
78
- reason : "The password should not be too common" ,
79
- } ;
80
- }
64
+ if (
65
+ checkWithCommonPasswords && passwordList != undefined &&
66
+ passwordList . includes ( password )
67
+ ) {
68
+ return {
69
+ isValid : false ,
70
+ reason : "The password should not be too common" ,
71
+ } ;
81
72
}
82
73
83
74
return { isValid : true } ;
0 commit comments