解讀ASP.NET密碼強(qiáng)度驗(yàn)證代碼實(shí)例分享
更新時間:2013年10月26日 16:18:08 作者:
這篇文章介紹了ASP.NET密碼強(qiáng)度驗(yàn)證代碼實(shí)例,有需要的朋友可以參考一下
效果如下:
輸入密碼:
密碼強(qiáng)度:
密碼強(qiáng)度:
| 弱 | 中 | 強(qiáng) |
代碼如下:
<%@ 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>無標(biāo)題頁</title>
</head>
<mce:script language="javascript" type="text/javascript"><!--
//CharMode函數(shù)
//測試某個字符是屬于哪一類.
function CharMode(iN){
if (iN>=48 && iN <=57) //數(shù)字
return 1;
if (iN>=65 && iN <=90) //大寫字母
return 2;
if (iN>=97 && iN <=122) //小寫
return 4;
else
return 8; //特殊字符
}
//bitTotal函數(shù)
//計算出當(dāng)前密碼當(dāng)中一共有多少種模式
function bitTotal(num){
modes=0;
for (i=0;i<4;i++){
if (num & 1) modes++;
num>>>=1;
}
return modes;
}
//checkStrong函數(shù)
//返回密碼的強(qiáng)度級別
function checkStrong(sPW){
if (sPW.length<=4)
return 0; //密碼太短
Modes=0;
for (i=0;i<sPW.length;i++){
//測試每一個字符的類別并統(tǒng)計一共有多少種模式.
Modes|=CharMode(sPW.charCodeAt(i));
}
return bitTotal(Modes);
}
//pwStrength函數(shù)
//當(dāng)用戶放開鍵盤或密碼輸入框失去焦點(diǎn)時,根據(jù)不同的級別顯示不同的顏色
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>
<body>
<form id="form1" runat="server">
<div>
輸入密碼:<asp:TextBox ID="TextBox1" runat="server" onKeyUp=pwStrength(this.value) onBlur=pwStrength(this.value) ></asp:TextBox><br />
密碼強(qiáng)度:
<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">
弱</td>
<td id="strength_M" style="width: 100px; height: 19px;" align="center">
中</td>
<td id="strength_H" style="width: 100px; height: 19px;" align="center">
強(qiáng)</td>
</tr>
</table>
</div>
</form>
</body>
</html>
復(fù)制代碼 代碼如下:
<%@ 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>無標(biāo)題頁</title>
</head>
<mce:script language="javascript" type="text/javascript"><!--
//CharMode函數(shù)
//測試某個字符是屬于哪一類.
function CharMode(iN){
if (iN>=48 && iN <=57) //數(shù)字
return 1;
if (iN>=65 && iN <=90) //大寫字母
return 2;
if (iN>=97 && iN <=122) //小寫
return 4;
else
return 8; //特殊字符
}
//bitTotal函數(shù)
//計算出當(dāng)前密碼當(dāng)中一共有多少種模式
function bitTotal(num){
modes=0;
for (i=0;i<4;i++){
if (num & 1) modes++;
num>>>=1;
}
return modes;
}
//checkStrong函數(shù)
//返回密碼的強(qiáng)度級別
function checkStrong(sPW){
if (sPW.length<=4)
return 0; //密碼太短
Modes=0;
for (i=0;i<sPW.length;i++){
//測試每一個字符的類別并統(tǒng)計一共有多少種模式.
Modes|=CharMode(sPW.charCodeAt(i));
}
return bitTotal(Modes);
}
//pwStrength函數(shù)
//當(dāng)用戶放開鍵盤或密碼輸入框失去焦點(diǎn)時,根據(jù)不同的級別顯示不同的顏色
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>
復(fù)制代碼 代碼如下:
<body>
<form id="form1" runat="server">
<div>
輸入密碼:<asp:TextBox ID="TextBox1" runat="server" onKeyUp=pwStrength(this.value) onBlur=pwStrength(this.value) ></asp:TextBox><br />
密碼強(qiáng)度:
<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">
弱</td>
<td id="strength_M" style="width: 100px; height: 19px;" align="center">
中</td>
<td id="strength_H" style="width: 100px; height: 19px;" align="center">
強(qiáng)</td>
</tr>
</table>
</div>
</form>
</body>
</html>
您可能感興趣的文章:
- ASP.NET?MVC5網(wǎng)站開發(fā)之添加、刪除、重置密碼、修改密碼、列表瀏覽管理員篇2(六)
- ASP.NET MVC5網(wǎng)站開發(fā)用戶修改資料和密碼(六)
- asp.net利用cookie保存用戶密碼實(shí)現(xiàn)自動登錄的方法
- ASP.NET 回發(fā)密碼框清空問題處理方法
- asp.net 生成隨機(jī)密碼的具體代碼
- asp.net中使用cookie與md5加密實(shí)現(xiàn)記住密碼功能的實(shí)現(xiàn)代碼
- 淺析ASP.NET生成隨機(jī)密碼函數(shù)
- asp.net membership 密碼重設(shè)
- ASP.net中md5加密碼的方法
- ASP.NET jQuery 實(shí)例13 原創(chuàng)jQuery文本框字符限制插件-TextArea Counter
- ASp.net 文本框(TextBox)計算,判斷輸入的是否是數(shù)字
- ASP.NET文本框密碼賦默認(rèn)值的方法
相關(guān)文章
Forms身份認(rèn)證在IE11下無法保存Cookie的問題
這篇文章主要介紹了Forms身份認(rèn)證在IE11下無法保存Cookie問題的解決方法,需要的朋友可以參考下2014-05-05
.NET之后臺用戶權(quán)限管理實(shí)現(xiàn)
在功能性比較強(qiáng)大的后臺管理網(wǎng)站處于各種角度考慮多有應(yīng)用權(quán)限管理功能。以公司內(nèi)部管理系統(tǒng)為例,管理員根據(jù)不同員工所在不同部門賦予其不同權(quán)限,或者根據(jù)上下級隸屬關(guān)系實(shí)現(xiàn)“金字塔”管理。本文內(nèi)容有不盡不實(shí)之處懇請指正。2013-02-02
asp.net下Response.ContentType類型匯總
asp.net下Response.ContentType類型匯總...2007-04-04
深入Lumisoft.NET組件POP3郵件接收與刪除操作的使用詳解
本篇文章對Lumisoft.NET組件POP3郵件接收與刪除操作的使用進(jìn)行了詳細(xì)的介紹。需要的朋友參考下2013-05-05
國產(chǎn)化之銀河麒麟安裝.NetCore包管理器方式(步驟詳解)
這篇文章主要介紹了國產(chǎn)化之銀河麒麟安裝.NetCore-包管理器方式,本文給大家分享安裝步驟及安裝命令,對銀河麒麟安裝.NetCore相關(guān)知識感興趣的朋友一起看看吧2022-03-03
ASP.NET實(shí)現(xiàn)用戶注冊和驗(yàn)證功能(第4節(jié))
這篇文章主要介紹了ASP.NET實(shí)現(xiàn)用戶注冊和驗(yàn)證功能,學(xué)習(xí)ASP.NET驗(yàn)證控件的作用和使用方法,在此基礎(chǔ)上了解常用第三方控件,需要的朋友可以參考一下2015-08-08

