Interpretation of asp.net password strength Verification Code instance sharing _ Practical skills

Source: Internet
Author: User
The effect is as follows:
Enter Password:
Password strength:
Weak In Strong
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>
&LT;TD id= "strength_l" style= "width:100px; HEIGHT:19PX "align=" Center ">
Weak </td>
&LT;TD id= "Strength_m" style= "width:100px; HEIGHT:19PX "align=" Center ">
Central </td>
&LT;TD id= "Strength_h" style= "width:100px; HEIGHT:19PX "align=" Center ">
Strong </td>
</tr>
</table>
</div>
</form>
</body>
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.