Posted on 2007-03-22 14:16
Jaunt 阅读(1276)
评论(1) 编辑 收藏 所属分类:
JavaScript
JS检验密码安全性等级:(首先声明,本文非我原作)
<STYLE type=text/css>
body {
font-size: 12px;
font-family: Tahoma, Arial;
background: #C4C8CB;
margin: 0px;
padding: 0px;
}
td {
padding-left: 5px;
font-size: 12px;
font-family: Tahoma, Arial;
}
.blueFont {color: #6699CC}
.redFont {color: #FF0000}
/***** Other Elements in Page Content *****/
.pwd-strength {
padding: 2px;
padding-left: 5px;
padding-right: 5px;
width: 180px;
border: solid 1px #CCCCCC;
}
.pwd-strength-box,
.pwd-strength-box-low,
.pwd-strength-box-med,
.pwd-strength-box-hi
{
color: #464646;
text-align: center;
width: 33%;
}
.pwd-strength-box-low
{
color: #990000;
background-color: #FFECEC;
}
.pwd-strength-box-med
{
color: #000066;
background-color: #D2E9FF;
}
.pwd-strength-box-hi
{
color: #003300;
background-color: #DDFFDD;
}
</STYLE>
<SCRIPT language=javascript>
function checkPassword(pwd){
var objLow=document.getElementById("pwdLow");
var objMed=document.getElementById("pwdMed");
var objHi=document.getElementById("pwdHi");
objLow.className="pwd-strength-box";
objMed.className="pwd-strength-box";
objHi.className="pwd-strength-box";
if(pwd.length<6){
objLow.className="pwd-strength-box-low";
}else{
var p1= (pwd.search(/[a-zA-Z]/)!=-1) ? 1 : 0;
var p2= (pwd.search(/[0-9]/)!=-1) ? 1 : 0;
var p3= (pwd.search(/[^A-Za-z0-9_]/)!=-1) ? 1 : 0;
var pa=p1+p2+p3;
if(pa==1){
objLow.className="pwd-strength-box-low";
}else if(pa==2){
objMed.className="pwd-strength-box-med";
}else if(pa==3){
objHi.className="pwd-strength-box-hi";
}
}
}
</SCRIPT>
<BR>
<TABLE borderColor=#ffffff cellSpacing=0 borderColorDark=#eeeeee cellPadding=0 width=400 align=center bgColor=#ffffff border=1>
<TBODY>
<TR>
<TD align=middle bgColor=#ffffcc colSpan=2 height=22><SPAN class=blueFont><B>校验密码安全性</B></SPAN></TD></TR>
<TR>
<TD style="WIDTH: 100px">请输入密码:</TD>
<TD><INPUT onkeyup=checkPassword(this.value); type=password value="" name=password></TD></TR>
<TR>
<TD style="WIDTH: 100px">安全性等级:</TD>
<TD>
<TABLE class="pwd-strength FCK__ShowTableBorders" cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD class=pwd-strength-box id=pwdLow>低</TD>
<TD class=pwd-strength-box id=pwdMed>中</TD>
<TD class=pwd-strength-box id=pwdHi>高</TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD colSpan=2><SPAN class=redFont>建议至少 6 个字符. 请使用强密码以保证安全.</SPAN></TD></TR></TBODY></TABLE>
from index:
http://www.cnitblog.com/yemoo/archive/2006/07/04/13219.html