Password Strength

巫马安怡
2023-12-01

前2天访问hotmail的Sign Up(注册)页面,发现现在页面越做越好了,其中一个Password Strength功能让我记忆犹新,它可以衡量1个密码的健壮度,试了几次果然不错。今天晚上没什么好看的电视,The Simpons又是看过的,what a usual night!!!于是随手自己写了个Password Strength,和Hotmail Sign Up页面上的差不多,Pretty Easy。
只要打开个记事本把下面的源码粘帖进去,保存文件主名无所谓,只要扩展名为htm或者html。用IE打开它,就可以enjoy yourself了。对了,今天是New Year's Eve,祝大家Happy New Year&Good Luck To My Exams呵呵.

<!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>
<title>Password Strength</title>
</head>
<body>
<script language="javascript">

function IsLetter(c){
return (c>='a' && c<='z') || (c>='A') && (c<='Z');
}

function IsNumber(c){
return (c>=0 && c<=9);
}

function IsSymbol(c){
return !IsLetter(c) && !IsNumber(c);
}

function IsSpace(c){
return c==' ';
}

function pwdTxt_onkeyup() {
var i;
var l,n,s
l=0;
n=0;
s=0;
for(i=0;i<pwdTxt.value.length;i++){
var c=pwdTxt.value.charAt(i);
if (IsSpace(c)){
pwdTxt.value=pwdTxt.value.substring(0,pwdTxt.value.length-1);
return;
}
if (IsLetter(c))
l=1;
if(IsNumber(c))
n=1;
if (IsSymbol(c))
s=1;
}

if ((l+n+s)==0){
Weak.style.background="lightgrey";
Weak.style.color="silver";
Medium.style.background=Weak.style.background;
Medium.style.color="silver";
Powerful.style.background=Weak.style.background;
Powerful.style.color="silver";
}

if ((l+n+s)==1){
Weak.style.background="red";
Weak.style.color="black";
Medium.style.background="lightgrey";
Medium.style.color="lightgrey";
Powerful.style.background="lightgrey";
Powerful.style.color="lightgrey";
}

if ((l+n+s)==2){
Weak.style.background="yellow";
Weak.style.color="yellow";
Medium.style.background="yellow";
Medium.style.color="Black";
Powerful.style.background="lightgrey";
Powerful.style.color="lightgrey";
}

if ((l+n+s)==3){
Weak.style.background="green";
Weak.style.color="green";
Medium.style.background="green";
Medium.style.color="green";
Powerful.style.background="green";
Powerful.style.color="black";
}

}

</script>

<input style="border-right: silver 1px solid; border-top: silver 1px solid;
border-left: silver 1px solid; width: 313px; border-bottom: silver 1px solid"
type="password" name="pwdTxt" language="javascript" οnkeyup="return pwdTxt_onkeyup()" maxlength="15"/><br />
<br />
<table>
<tr>
<td style="border-right: gray 1px solid; border-top: gray 1px solid; border-left: gray 1px solid;
width: 100px; border-bottom: gray 1px solid; background-color: lightgrey; color: silver; text-align: left;" id="Weak">
<span style="font-size: 10pt; font-family: Tahoma">
Weak</span></td>
<td style="border-right: gray 1px solid; border-top: gray 1px solid; border-left: gray 1px solid;
width: 100px; border-bottom: gray 1px solid; background-color: lightgrey; text-align: center; color: silver;" id="Medium">
<span style="font-size: 10pt; font-family: Tahoma">
Medium</span></td>
<td style="border-right: gray 1px solid; border-top: gray 1px solid; border-left: gray 1px solid;
width: 100px; border-bottom: gray 1px solid; color: silver; background-color: lightgrey; text-align: right;" id="Powerful">
<span style="font-size: 10pt; font-family: Tahoma">
Powerful</span></td>
</tr>
</table>

</body>
</html>

 类似资料:

相关阅读

相关文章

相关问答