Preface:
Password strength is a common function and is relatively simple. It is mainly about how to develop this strength rule. Now, you need to verify the password strength. The previous verification is relatively simple and cannot meet your needs. Now you need a password strength verification that can be flexibly changed and can be configured at multiple levels, so we designed the following stuff. Before the design, I also referred to the more mature strength rules, which are similar. Almost all of them adopted the scoring mechanism to control the password strength rules, which is highly configurable and flexible. I wanted to use it directly, but I found that it was relatively old. Some of them were not suitable for the company's development needs. Maybe this is simple, so no one has to update and write new ones.CodeSo I designed the rules and wrote the code myself.
Implementation:
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.
Code: Copy code The Code is as follows: 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;
}
scoring example:
1111 = 7
1 @ da = 20
111111 = 9
abcdef1 = 19
abcd12 = 18
ABC123 = 18 points
ab123a = 22 points
aa12j = 26 Points
aasdfkjjsjjj = 16 points
111111111 dsfskjjkjeh = 25 points
1111 dsfskjjkjeh = 25 points
1231kb #4 ktsf! T @ s ^ J # hkwh = 50 points
skhk3293ks = 24 Points
SFH #4 hhdk = 29 points
bure12 # Sk = 27 points
@ s @ dk23 = 26 Points
bruceli @ 09kt = 34 points
Ce @ Li1 = 24 Points
end
it's over here, you are welcome to discuss this scoring rule. You can also directly give your own written rules and code to facilitate your research and communication. The code needs to be maintained and updated continuously, in this way, we can proceed on the script of our predecessors.