Password strength prompts, such as Youku, are often visible when registering on some sites:
Today I did a JS password strength judgment, the effect is as follows:
Here's the code:
Copy Code code as follows:
<title>js Judgment Password Strength </title>
<script language=javascript>
Determine the type of password entered
function Charmode (in) {
if (in>=48 && in <=57)//number
return 1;
if (in>=65 && in <=90)//Uppercase
return 2;
if (in>=97 && in <=122)//lowercase
return 4;
Else
return 8;
}
Bittotal function
Calculate password mode
function Bittotal (num) {
modes=0;
for (i=0;i<4;i++) {
if (num & 1) modes++;
num>>>=1;
}
return modes;
}
Return strength level
function Checkstrong (SPW) {
if (spw.length<=4)
return 0; Password is too short
modes=0;
for (i=0;i<spw.length;i++) {
Password mode
Modes|=charmode (Spw.charcodeat (i));
}
Return Bittotal (Modes);
}
Display Color
function Pwstrength (pwd) {
O_color= "#eeeeee";
L_color= "#FF0000";
M_color= "#FF9900";
H_color= "#33CC00";
if (pwd==null| | pwd== ') {
Lcolor=mcolor=hcolor=o_color;
}
else{
S_level=checkstrong (PWD);
Switch (s_level) {
Case 0:
Lcolor=mcolor=hcolor=o_color;
Case 1:
Lcolor=l_color;
Mcolor=hcolor=o_color;
Break
Case 2:
Lcolor=mcolor=m_color;
Hcolor=o_color;
Break
Default
Lcolor=mcolor=hcolor=h_color;
}
}
document.getElementById ("strength_l"). Style.background=lcolor;
document.getElementById ("Strength_m"). Style.background=mcolor;
document.getElementById ("Strength_h"). Style.background=hcolor;
Return
}
</script>
<body>
<form name=form1 action= "" >
<table width= "border=" 0 "cellpadding=2" bordercolor= "#eeeeee" style= ' Display:inline ' >
<tr>
<TD width= "40%" align= "right" > Password:</td>
<TD colspan= "3" align= "left" >
<input Type=password size=20 onkeyup=pwstrength (this.value) onblur=pwstrength (this.value) >
</td>
</tr>
<TR align= "center" >
<TD width= "40%" align= "right" > Password strength:</td>
<TD width= "20%" id= "strength_l" bgcolor= "#f5f5f5" > Weak </td>
<TD width= "20%" id= "Strength_m" bgcolor= "#f5f5f5" > </td>
<TD width= "20%" id= "Strength_h" bgcolor= "#f5f5f5" > Strong </td>
</tr>
</table>
</form>
</body>