The effect is as follows:
Enter Password:
Password strength:
The code is as follows:
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Untitled Page </title>
<mce:script language= "javascript" type= "Text/javascript" ><!--
Charmode function
Test what kind of character it belongs to.
function Charmode (in) {
if (in>=48 && in <=57)//number
return 1;
if (in>=65 && in <=90)//Uppercase
return 2;
if (in>=97 && in <=122)//lowercase
return 4;
Else
return 8; Special characters
}
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 a 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
Displays different colors at different levels when the user releases the keyboard or password input box from losing focus
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);
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
}
--></mce:script>
Copy Code code as follows:
<body>
<form id= "Form1" runat= "Server" >
<div>
Enter Password: <asp:textbox id= "TextBox1" runat= "Server" Onkeyup=pwstrength (this.value) onblur=pwstrength (this.value) > </asp:textbox><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 ">
Central </td>
<TD id= "Strength_h" style= "width:100px; HEIGHT:19PX "align=" Center ">
Strong </td>
</tr>
</table>
</div>
</form>
</body>