HTML code:
1 <formname= "Form1"Action="">2Password:<inputtype= "Password"size= "8"onkeyup= "Pwstrength (this.value)"onblur= "Pwstrength (this.value)">3 <BR>4 Password Strength:5 <Tablewidth= "220px"Border= "1"cellspacing= "0"cellpadding= "1"bordercolor= "#eeeeee"Height= "22px">6 <TRAlign= "Center"bgcolor= "#f5f5f5">7 <TDwidth= "33%"ID= "strength_l">Weak</TD>8 <TDwidth= "33%"ID= "Strength_m">In</TD>9 <TDwidth= "33%"ID= "Strength_h">Strong</TD>Ten </TR> One </Table> A </form>
JS Code:
1 functionPwdstrength (pwd) {2O_color = "#eeeeee";3L_color = "#FF0000";4M_color = "#FF9900";5H_color = "#33CC00";6 varLevel = 0, strength = "O";7 if(pwd = =NULL|| PWD = = ") {8Strength = "O";9Lcolor = Mcolor = Hcolor =O_color;Ten } One Else { A varmode = 0; - if(Pwd.length <= 4) -mode = 0; the Else { - for(i = 0; i < pwd.length; i++) { - varCharmode, CharCode; -CharCode =pwd.charcodeat (i); + //determine the type of password entered - if(CharCode >= && charcode <= 57)//Digital +Charmode = 1; A Else if(CharCode >= && charcode <= 90)//Uppercase atCharmode = 2; - Else if(CharCode >= && charcode <= 122)//lowercase -Charmode = 4; - Else -Charmode = 8; -Mode |=Charmode; in } - //Calculate password Mode toLevel = 0; + for(i = 0; i < 4; i++) { - if(Mode & 1) thelevel++; *Mode >>>= 1; $ }Panax Notoginseng } - Switch(level) { the Case0: +Strength = "O"; ALcolor = Mcolor = Hcolor =O_color; the Break; + Case1: -Strength = "L"; $Lcolor =L_color; $Mcolor = Hcolor =O_color; - Break; - Case2: theStrength = "M"; -Lcolor = Mcolor =M_color;WuyiHcolor =O_color; the Break; - default: WuStrength = "H"; -Lcolor = Mcolor = Hcolor =H_color; About Break; $ } - } -document.getElementById ("strength_l"). Style.background =Lcolor; -document.getElementById ("Strength_m"). Style.background =Mcolor; Adocument.getElementById ("Strength_h"). Style.background =Hcolor; + returnstrength; the}