Function passwordGrade (pwd ){
Var score = 0;
Var regexArr = ['[0-9]', '[a-z]', '[A-Z]', '[\ W _]'];
Var repeatCount = 0;
Var prevChar = '';
// Check length
Var len = pwd. length;
Score + = len> 18? 18: len;
// Check type
For (var I = 0, num = regexArr. length; I <num; I ++) {if (eval ('/' + regexArr [I] + '/'). test (pwd) score + = 4 ;}
// Bonus point
For (var I = 0, num = regexArr. length; I <num; I ++ ){
If (pwd. match (eval ('/' + regexArr [I] + '/g') & pwd. match (eval ('/' + regexArr [I] + '/g ')). length> = 2) score + = 2;
If (pwd. match (eval ('/' + regexArr [I] + '/g') & pwd. match (eval ('/' + regexArr [I] + '/g ')). length> = 5) score + = 2;
}
// Deduction
For (var I = 0, num = pwd. length; I <num; I ++ ){
If (pwd. charAt (I) = prevChar) repeatCount ++;
Else prevChar = pwd. charAt (I );
}
Score-= repeatCount * 1;
Return score;
}
Principle:
Using the scoring mechanism, scores are divided into three categories (basic score, plus points, and minus points). The base score is obtained first, and the final total score is calculated after the score is deducted.
Rules:
The password can be of the following type: uppercase letters, lowercase letters, and special characters ).
It can be divided into the password length. The password can be 1 minute and more than 18 characters are all 18 minutes. The password contains an input type, with a base score of 4 points.
If the total number of passwords is greater than or equal to 2, the total number is 2. If the total number is greater than or equal to 5, the total number is 4 points.
If a single type of characters that have been repeatedly repeated consecutively, the score is reduced by 1 point at a time.
Total score: 50.
0 ~ 10 points: unqualified (weak)
11 ~ 20 points: Average
21 ~ 30 minutes: Medium
31 ~ 40 points: Strong
41 ~ 50 points: Security
* The score range can be adjusted and matched freely. In fact, the entire scoring rule can be modified as needed.