Verify password strength from Google

Source: Internet
Author: User

 Four types of Combination Numbers, lowercase letters, uppercase letters, and other characters

Divide the password strength into four levels:

1.The password must be less than or equal to 6 characters in length. Or there is only one combination of passwords.
2. The password must be six characters in length and can be used in combination.
3.The password is more than 6 characters long and can be combined into three types.
4.The password is more than 6 characters long and can be combined into four types.

If no value is input, return0

Demo
<Table>
<Tbody>
<Tr>
<TD> password: </TD>
<TD> <input id = PWD onkeyup = createratepasswdreq (this); type = password value = ""> <span style = "font-family: Arial, sans-serif "> the length must contain at least 6 characters. </Span>
<Table cellspacing = 0 cellpadding = 0 border = 0>
<Tbody>
<Tr>
<TD valign = Top nowrap width = 0> <font face = "Arial, sans-serif" size =-1> password strength: </font> </TD>
<TD valign = Top nowrap> <font face = "Arial, sans-serif" color = #808080 size =-1> <strong>
<Div id = passwdrating> </div>
</Strong> </font> </TD>
</Tr>
<Tr>
<TD Height = 3> </TD>
</Tr>
<Tr>
<TD colspan = 2>
<Table id = passwdbar cellspacing = 0 cellpadding = 0 width = 180 bgcolor = # ffffff border = 0>
<Tbody>
<Tr>
<TD id = posbar width = 0% bgcolor = # e0e0e0 Height = 4> </TD>
<TD id = negbar width = "100%" bgcolor = # e0e0e0 Height = 4> </TD>
</Tr>
</Tbody>
</Table>
</TD>
</Tr>
</Tbody>
</Table>
</TD>
</Tr>
</Tbody>
</Table>
<SCRIPT>

Ratingmsgs = new array (6 );
Ratingmsgcolors = new array (6 );
Barcolors = new array (6 );
Ratingmsgs [0] = "Too short ";
Ratingmsgs [1] = "weak ";
Ratingmsgs [2] = "normal ";
Ratingmsgs [3] = "good ";
Ratingmsgs [4] = "excellent ";
Ratingmsgs [5] = "unrated"; // if the password server is down
Ratingmsgcolors [0] = "#676767 ";
Ratingmsgcolors [1] = "# aa0033 ";
Ratingmsgcolors [2] = "# f5ac00 ";
Ratingmsgcolors [3] = "# 6699cc ";
Ratingmsgcolors [4] = "#008000 ";
Ratingmsgcolors [5] = "#676767 ";
Barcolors [0] = "# dddddddd ";
Barcolors [1] = "# aa0033 ";
Barcolors [2] = "# ffcc33 ";
Barcolors [3] = "# 6699cc ";
Barcolors [2] = "#008000 ";
Barcolors [5] = "#676767 ";
Function createratepasswdreq (PWD ){
If (! Isbrowsercompatible ){
Return;
}

// If (! Document. getelementbyid) return false;
// Var Pwd = Document. getelementbyid ("PWD ");
If (! PWD) return false;
Passwd = PWD. value;
VaR min_passwd_len = 6;
If (passwd. Length <min_passwd_len ){
If (passwd. length> 0 ){
Drawbar (0 );
} Else {
Resetbar ();
}
} Else {
// We need to escape the password now so it won't mess up with length Test
Rating = checkpasswdrate (passwd );
Drawbar (rating );

}
}
Function getelement (name ){
If (document. All ){
Return document. All (name );
}
Return document. getelementbyid (name );
}

Function drawbar (rating ){
VaR posbar = getelement ('posbar ');
VaR negbar = getelement ('negbar ');
VaR passwdrating = getelement ('passwdrating ');
VaR barlength = getelement ('passdbar '). width;
If (rating> = 0 & rating <= 4) {// We successfully got a rating
Posbar. style. width = barlength/4 * rating + "PX ";
Negbar. style. width = barlength/4 * (4-rating) + "PX ";
} Else {
Posbar. style. width = "0px ";
Negbar. style. width = barlength + "PX ";
Rating = 5; // not rated rating
}
Posbar. style. Background = barcolors [Rating];
Passwdrating. innerhtml = "<font color = '" + ratingmsgcolors [Rating] +
"'>" + Ratingmsgs [Rating] + "</font> ";
}

// Resets the password strength bar back to its initial state without any message showing.
Function resetbar (){
VaR posbar = getelement ('posbar ');
VaR negbar = getelement ('negbar ');
VaR passwdrating = getelement ('passwdrating ');
VaR barlength = getelement ('passdbar '). width;
Posbar. style. width = "0px ";
Negbar. style. width = barlength + "PX ";
Passwdrating. innerhtml = "";
}
/* Checks browser compatibility */
VaR AGT = navigator. useragent. tolowercase ();
VaR is_op = (AGT. indexof ("Opera ")! =-1 );
VaR is_ie = (AGT. indexof ("MSIE ")! =-1) & document. All &&! Is_op;
VaR is_mac = (AGT. indexof ("Mac ")! =-1 );
VaR is_gk = (AGT. indexof ("gecko ")! =-1 );
VaR is_sf = (AGT. indexof ("safari ")! =-1 );
Function gff (STR, pfx ){
VaR I = Str. indexof (pfx );
If (I! =-1 ){
VaR v = parsefloat (Str. substring (I + pfx. Length ));
If (! Isnan (V )){
Return V;
}
}
Return NULL;
}
Function compatible (){
If (is_ie &&! Is_op &&! Is_mac ){
VaR v = gff (AGT, "MSIE ");
If (V! = NULL ){
Return (V >=6.0 );
}
}
If (is_gk &&! Is_sf ){
VaR v = gff (AGT, "RV :");
If (V! = NULL ){
Return (V >=1.4 );
} Else {
V = gff (AGT, "galeon /");
If (V! = NULL ){
Return (V >=1.3 );
}
}
}
If (is_sf ){
VaR v = gff (AGT, "applewebkit /");
If (V! = NULL ){
Return (V >=124 );
}
}
Return false;
}

/* We also try to create an XMLHTTP object to see if the browser supports it */
VaR isbrowsercompatible = compatible ();

// charmode function
// test the type of a character.
function charmode (in) {
If (in> = 48 & in <= 57) // number
return 1;
If (in> = 65 & in <= 90) // uppercase letter
return 2;
If (in >=97 & in <= 122) // lower case
return 4;
else
return 8; // special character
}< br> // bittotal function
// calculate the total number of modes in the current password
function bittotal (Num) {
modes = 0;
for (I = 0; I <4; I ++) {
If (Num & 1) modes ++;
num >>>= 1;
}< br> return modes;
}< br> // checkstrong function
// return the password strength level
function checkpasswdrate (spw) {
If (spw. length <= 4)
return 0; // The password is too short
modes = 0;
for (I = 0; I // test the category of each character and count the total number of modes.
modes | = charmode (spw. charcodeat (I);
}< br> return bittotal (modes);
}< br>

</SCRIPT>

 

Demo

Password: It must contain at least 6 characters.

Password strength:

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.