1. Create the default. aspx file. The Code is 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">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<Script language = "JavaScript" type = "text/JavaScript">
// Charmode Function
// Test the category of a character.
Function charmode (in ){
If (in> = 48 & in <= 57) // number
Return 1;
If (in> = 65 & in <= 90) // uppercase letter
Return 2;
If (in> = 97 & in <= 122) // lower case
Return 4;
Else
Return 8; // special characters
}
// Bittotal Function
// Calculate the total number of modes 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
// Return the password strength level
Function checkstrong (spw ){
If (spw. Length <= 4)
Return 0; // The password is too short
Modes = 0;
For (I = 0; I <spw. length; I ++ ){
// Test the category of each character and calculate the total number of modes.
Modes | = charmode (spw. charcodeat (I ));
}
Return bittotal (modes );
}
// Pwstrength Function
// When the user releases the keyboard or loses the focus in the password input box, different colors are displayed based on different levels
Function pwstrength (PWD ){
O_color = "# e0f0ff ";
Rochelle 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>
<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 = "#99 CCFF" 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">
Medium </TD>
<TD id = "strength_h" style = "width: 100px; Height: 19px;" align = "center">
Strong </TD>
</Tr>
</Table>
</Div>
</Form>
</Body>
</Html>
2. The default. aspx. CS code is as follows:
Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
}
}
3: The running effect is as follows:
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/mengyao/archive/2007/09/11/1781134.aspx