Last Update:2017-08-24
Source: Internet
Author: User
Keywords
Web page production
Ajax
javascript
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html xmlns= "http://www.jzread.com/1999/xhtml" > <head id= "Head1" runat= "Server" > <title> Password strength test </title> </head> <script language= "javascript" type= "Text/javascript" > //charmode function //test what kind of character it belongs to. function Charmode (in) { if (in>=48 && in <=57)//Digital return 1; if (in>=65 && in <=90)//Capital Letter return 2; if (in>=97 && in <=122)//lowercase return 4; Else return 8; Special character } //bittotal function //Calculates how many patterns there are in the current password function bittotal (num) { modes=0; for (i=0;i<4;i++) { if (num & 1) modes++; num>>>=1; } return modes; } //checkstrong function //Returns the strength level of the password function Checkstrong (sPW) { if (spw.length<=4) return 0; Password is too short modes=0; for (i=0;i<spw.length;i++) { //test the category of each character and count how many patterns there are. Modes|=charmode (Spw.charcodeat (i)); } return Bittotal (Modes); } //pwstrength function ////When the user releases the keyboard or password input box to lose focus, display different colors according to different levels function Pwstrength (pwd) { o_color= "#e0f0ff"; l_color= "#FF0000"; m_color= "#FF9900"; h_color= "#33CC00"; if (pwd==null| | pwd== ') { Lcolor=mcolor=hcolor=o_color; } Else { S_level=checkstrong (PWD); //alert (S_level); 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 id= "Form1" > <div> Enter Password: <input type= "text" id= "TextBox1" onkeyup= "Pwstrength (this.value)" onblur= "Pwstrength (this.value)" >< Br> Password Strength: <table border= "1" cellpadding= "1" bordercolordark= "#fdfeff" bordercolorlight= "#99ccff" cellspacing= "1" style= "width:200px; Display:inline; Background-color: #e0f0ff "> <tr> <td id= "strength_l style=" width:100px; HEIGHT:19PX "align=" center "> Weak </td> <td id= "Strength_m style=" width:100px; HEIGHT:19PX "align=" center "> </td> <td id= "Strength_h style=" width:100px; HEIGHT:19PX "align=" center "> Strong </td> </tr> </table> </div> </form> </body> </html>