解讀ASP.NET密碼強(qiáng)度驗(yàn)證代碼實(shí)例分享
更新時(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ù)
//計(jì)算出當(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)計(jì)一共有多少種模式.
Modes|=CharMode(sPW.charCodeAt(i));
}
return bitTotal(Modes);
}
//pwStrength函數(shù)
//當(dāng)用戶放開鍵盤或密碼輸入框失去焦點(diǎn)時(shí),根據(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ù)
//計(jì)算出當(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)計(jì)一共有多少種模式.
Modes|=CharMode(sPW.charCodeAt(i));
}
return bitTotal(Modes);
}
//pwStrength函數(shù)
//當(dāng)用戶放開鍵盤或密碼輸入框失去焦點(diǎn)時(shí),根據(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)計(jì)算,判斷輸入的是否是數(shù)字
- ASP.NET文本框密碼賦默認(rèn)值的方法
相關(guān)文章
C#反射實(shí)例學(xué)習(xí)及注意內(nèi)容
C#反射的入門學(xué)習(xí)首先要明白C#反射提供了封裝程序集、模塊和類型的對象等等需要的朋友可以參考下2012-12-12asp.net mvc 從數(shù)據(jù)庫中讀取圖片的實(shí)現(xiàn)代碼
今天搞了一天的MVC,在顯示圖片的時(shí)候老是出現(xiàn)問題,從網(wǎng)上搜索了好久,才找到解決方法。2010-05-05如何使用Rotativa在ASP.NET Core MVC中創(chuàng)建PDF詳解
這篇文章主要給大家介紹了關(guān)于如何使用Rotativa在ASP.NET Core MVC中創(chuàng)建PDF的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-02-02關(guān)于DDD:管理"工作單元實(shí)例"的兩種模式的使用方法
本篇文章介紹了,關(guān)于DDD:管理"工作單元實(shí)例"的兩種模式的使用方法。需要的朋友參考下2013-04-04如何在ASP.NET Core 的任意類中注入Configuration
這篇文章主要介紹了如何在 ASP.NET Core 的任意類中注入Configuration ,幫助大家更好的理解和學(xué)習(xí)使用.net技術(shù),感興趣的朋友可以了解下2021-04-04ASP.NET動態(tài)生成靜態(tài)頁面的實(shí)例代碼
生成靜態(tài)頁有很多好處,可以緩解服務(wù)器壓力、方便搜索網(wǎng)站搜索等等,下面介紹一下生成靜態(tài)頁的實(shí)例代碼,有需要的朋友可以參考一下2013-07-07ASP.NET中基于soaphead的webservice安全機(jī)制
常會用到WebService來通訊,但WebService發(fā)布后為了能調(diào)用,一般都通過發(fā)布到IIS后調(diào)用 的。在IIS里可以通過匿名訪問,但這樣大家都可能訪問,不安全,下面提供一種基于soaphead的安全機(jī)制。2016-05-05利用ASP.NET MVC+EasyUI+SqlServer搭建企業(yè)開發(fā)框架
本文主要介紹使用asp.net mvc4、sqlserver、jquery2.0和easyui1.4.5搭建企業(yè)級開發(fā)框架的過程,希望能夠幫到大家。2016-04-04