Online reprint of a piece of code, save for later use,
JS file:
Determine the type of password entered
function Charmode (in) {
if (in>=48 && in <=57)//Digital
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; The 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
}
Page:
<td>
<table border= "0" ><TR >
<TD style= "padding:0px;border-top-width:0px; Border-right: #ff0000 0px solid; Border-left: #ff0000 0px solid; Border-top-color: #ff0000; Border-bottom: #ff0000 0px solid; " >
<input id= "password" name= "password" Type=password size=8 onkeyup=pwstrength (this.value) onblur=pwstrength ( This.value) ></td>
<TD style= "padding:0px;border-top-width:0px; Border-right: #ff0000 0px solid; Border-left: #ff0000 0px solid; Border-top-color: #ff0000; Border-bottom: #ff0000 0px solid; " >
<span id= "Sp_6" style= "color:red;" ></span>
</td>
<TD style= "padding:0px;border-top-width:0px; Border-right: #ff0000 0px solid; Border-left: #ff0000 0px solid; Border-top-color: #ff0000; Border-bottom: #ff0000 0px solid; " >
<table width= "border=" 0 "cellspacing=" 0 "cellpadding=" 1 "bordercolor=" #eeeeee "height=" style= "Display: Inline ' >
<TR align= "center" bgcolor= "#f5f5f5" >
<TD width= "33%" id= "strength_l" > Weak </td>
<TD width= "33%" id= "Strength_m" > </td>
<TD width= "33%" id= "Strength_h" > Strong </td>
</tr>
</table>
</td>
</tr>
</table>
</td>