<! 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>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.