Js User Password strength verification function

Source: Internet
Author: User
Js calls this function and returns the password strength level functiongetStrength (passwd) {intScore0; if (passwd. match (/[a-z]/) // [verify] at least one lowercase letter {intScore (int... syntaxHighlighter. all ();

Js calls this function and returns the password strength level
 

Function getStrength (passwd) {intScore = 0; if (passwd. match (/[a-z]/) // [verify] at least one lowercase letter {intScore = (intScore + 1)} if (passwd. match (/[A-Z]/) // [validate] at least one uppercase letter {intScore = (intScore + 5)} // single verify if (passwd. match (// d +/) // [verify] at least one number {intScore = (intScore + 5)} if (passwd. match (/d. */d. */d)/) // [verify] at least three digits {intScore = (intScore + 5)} // verify if (passwd. match (/[!, @ # $ % ^ &*? _ ~] /) // [Verify] at least one special character {intScore = (intScore + 5)} if (passwd. match (/([!, @ # $ % ^ &*? _ ~]. *[!, @ # $ % ^ &*? _ ~]) /) // [Verify] at least two special characters {intScore = (intScore + 5)} // composite verify if (passwd. match (/[a-z]/) & passwd. match (/[A-Z]/) // [validate] contains both upper and lower case {intScore = (intScore + 2)} if (passwd. match (// d/) & passwd. match (// D/) // [verification] contains both letters and numbers {intScore = (intScore + 2)} // [verification] contains both uppercase and lowercase letters, number and special character if (passwd. match (/[a-z]/) & passwd. match (/[A-Z]/) & passwd. match (// d/) & passwd. match (/[!, @ # $ % ^ &*? _ ~] /) {IntScore = (intScore + 2)} return intScore;} function getStrength (passwd) {intScore = 0; if (passwd. match (/[a-z]/) // [verify] at least one lowercase letter {intScore = (intScore + 1)} if (passwd. match (/[A-Z]/) // [validate] at least one uppercase letter {intScore = (intScore + 5)} // single verify if (passwd. match (// d +/) // [verify] at least one number {intScore = (intScore + 5)} if (passwd. match (/d. */d. */d)/) // [verify] at least three digits {intScore = (intScore + 5)} // if (Passwd. match (/[!, @ # $ % ^ &*? _ ~] /) // [Verify] at least one special character {intScore = (intScore + 5)} if (passwd. match (/([!, @ # $ % ^ &*? _ ~]. *[!, @ # $ % ^ &*? _ ~]) /) // [Verify] at least two special characters {intScore = (intScore + 5)} // composite verify if (passwd. match (/[a-z]/) & passwd. match (/[A-Z]/) // [validate] contains both upper and lower case {intScore = (intScore + 2)} if (passwd. match (// d/) & passwd. match (// D/) // [verification] contains both letters and numbers {intScore = (intScore + 2)} // [verification] contains both uppercase and lowercase letters, number and special character if (passwd. match (/[a-z]/) & passwd. match (/[A-Z]/) & passwd. match (// d/) & passwd. match (/[!, @ # $ % ^ &*? _ ~] /) {IntScore = (intScore + 2)} return intScore;

} Another method. Use a regular expression to verify the password strength. The password consists of 6 digits or characters and must contain one digit and one character.


 

^ (? = \ D {0, 5} [a-zA-Z]) (? = [A-zA-Z] {} \ d) [a-zA-Z0-9] {6} $ ^ (? = \ D {0, 5} [a-zA-Z]) (? = [A-zA-Z] {} \ d) [a-zA-Z0-9] {6} $1. a ^ [a-zA-Z0-9] {6} $ match the entire password string

2. Next, an asserted that the verification password must contain characters (? = \ D {0, 5} [a-zA-Z])

3. Similar to step 1, it is also an asserted that the verification password must contain numbers (? = [A-zA-Z] {0, 5} \ d)

 

Related Article

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.