Js password strength verification rules, scoring, verification code

Source: Internet
Author: User

 

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.