<TITLE>FLYSO blog--Password Strength </title>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<body>
User password:
<input type= "password" name= "pwd" onblur= "chkpwd (This)"/>
<div id= "Chkresult" ></div>
</body>
<script type= "Text/javascript" >
function Chkpwd (obj) {
var T=obj.value;
var id=getresult (t);
Define the corresponding message prompt
var msg=new Array (4);
msg[0]= "Password is too short. ";
msg[1]= "Password strength is poor. ";
msg[2]= "Password strength is good. ";
msg[3]= "Password strength is high. ";
var sty=new Array (4);
sty[0]=-45;
sty[1]=-30;
sty[2]=-15;
sty[3]=0;
var col=new Array (4);
Col[0]= "Gray";
col[1]= "Red";
Col[2]= "#ff6600";
Col[3]= "Green";
Set the display effect
var bimg= "myfile/images/pwdpic1.gif";//a picture used for display
var swidth=300;
var sheight=15;
var Bobj=document.getelementbyid ("Chkresult");
Bobj.style.fontsize= "12px";
Bobj.style.color=col[id];
Bobj.style.width=swidth + "px";
Bobj.style.height=sheight + "px";
Bobj.style.lineheight=sheight + "px";
bobj.style.background= "url (" + bimg + ") No-repeat Left" + sty[id] + "px";
Bobj.style.textindent= "20px";
Bobj.innerhtml= "detection hint:" + msg[id];
}
Define detection functions, return 0/1/2/3 for invalid/poor/general/strong
function GetResult (s) {
if (S.length < 4) {
return 0;
}
var ls = 0;
if (S.match (/[a-z]/ig)) {
ls++;
}
if (S.match (/[0-9]/ig)) {
ls++;
}
if (S.match (/(. [ ^a-z0-9]) (/ig)) {
ls++;
}
if (S.length < 6 && ls > 0) {
ls--;
}
return LS
}
</script>
js-Password Complexity