<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
<html xmlns= "http://www.w3.org/1999/xhtml"
<head>
<meta http-equiv= "Content-type" content= "HTML; Charset=utf-8 "/>
<title> simple JS implementation to detect user password security </title>
<script language=javascript>
// The Charmode function
//tests which type of character is part of
function Charmode (in) {
if (in>=48 && in <=57)/number
return 1;
if (in>=65 && in <=90)//capital Letter
Return 2;
if (in>=97 && in <=122)//lowercase
return 4;
else
return 8;//special characters
}
//bittotal function
//The total number of modes
function bittotal (num) {
modes=0;
for (i=0;i<4;i++) {
if (num & 1) modes++;
Num>>>=1;
}
return modes;
}
//checkstrong function
//Return password strength level
function Checkstrong (sPW) {
if (spw.length<=4)
returns 0;//password Too short
Modes=0;
for (i=0;i<spw.length;i++) {
//test the category of each character and count the total number of modes
Modes|=charmode (Spw.charcodeat (i));
}
return Bittotal (Modes);
}
//pwstrength function
//When user releases keyboard or password input box loses focus, different colors appear according to different levels
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>
</head>
<body>
<form name= "Form1" action= ""
Enter Password: <input type= "password" onkeyup= "Pwstrength" (this.value) "onblur=" Pwstrength (this.value) "><br>
Password strength: <table width=" 217 "border=" 1 "cellspacing=" 0 "cellpadding=" 1 " Bordercolor= "#cccccc"
height= "style=" Display:inline
<tr align= "center" bgcolor= "#eeeeee" >
<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>
</form>
<p Style= "margin-top:50px;" > Find more code, please visit: <a href= "http://www.jzread.com" target= "_blank" > Web page Production tutorial </a></p>
</body>
</html>