JavaScript user Registration Password strength test

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax document function how many html http javascript password

<! 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>

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.