Javascript| Source Code
1.Body Code Section
<body>
<table width= "100%" border= "0" cellspacing= "1" cellpadding= "0" >
<tr>
<TD width= "align=" "right" > intensity display:</td>
<td>
<script language= "JavaScript" >
var ps = new Passwordstrength ();
Ps.setsize ("200", "20");
Ps.setminlength (5);
</script>
</td>
</tr>
<tr>
<TD align= "Right" > Password detection:</td>
<td><input name= "pwd" type= "password" "id=" pwd "style=" width:200px "onkeyup=" Ps.update (this.value); " ></td>
</tr>
</table>
</body>
2.JS Code Section
Password strength;
function Passwordstrength (showed) {
this.showed = (typeof (showed) = = "Boolean")? Showed:true;
This.styles = new Array ();
This.styles[0] = {backgroundcolor: "#EBEBEB", Borderleft: "Solid 1px #FFFFFF", BorderRight: "Solid 1px #BEBEBE", BorderBottom: "Solid 1px #BEBEBE"};
This.styles[1] = {backgroundcolor: "#FF4545", Borderleft: "Solid 1px #FFFFFF", BorderRight: "Solid 1px #BB2B2B", BorderBottom: "Solid 1px #BB2B2B"};
This.styles[2] = {backgroundcolor: "#FFD35E", Borderleft: "Solid 1px #FFFFFF", BorderRight: "Solid 1px #E9AE10", BorderBottom: "Solid 1px #E9AE10"};
This.styles[3] = {backgroundcolor: "#95EB81", Borderleft: "Solid 1px #FFFFFF", BorderRight: "Solid 1px #3BBC1B", BorderBottom: "Solid 1px #3BBC1B"};
this.labels= ["Weak", "medium", "strong"];
This.divname = "Pwd_div_" +math.ceil (Math.random () *100000);
This.minlen = 5;
This.width = "150px";
This.height = "16px";
This.content = "";
This.selectedindex = 0;
This.init ();
}
PasswordStrength.prototype.init = function () {
var s = ' <table cellpadding= ' 0 "id=" ' +this.divname+ ' _table ' cellspacing= ' 0 "style=" width: ' +this.width+ '; height: ' + this.height+ '; ' > ';
s + + ' <tr> ';
for (Var i=0;i<3;i++) {
s + = ' <td id= ' ' +this.divname+ ' _td_ ' +i+ ' "width=" 33% "align=" center "><span style=" font-size:1px "> </ Span><span id= "' +this.divname+ ' _label_ ' +i+ '" style= "Display:none;font-family:courier New, Courier, mono; Font-size:12px;color: #000000; " > ' +this.labels[i]+ ' </span></td> ';
}
s + + ' </tr> ';
s + + ' </table> ';
This.content = s;
if (this.showed) {
document.write (s);
This.copytostyle (This.selectedindex);
}
}
PasswordStrength.prototype.copyToObject = function (O1,o2) {
for (var i in O1) {
O2[i] = O1[i];
}
}
PasswordStrength.prototype.copyToStyle = function (ID) {
This.selectedindex = ID;
for (Var i=0;i<3;i++) {
if (i = = id-1) {
this.$ (this.divname+ "_label_" +i). style.display = "inline";
}else{
this.$ (this.divname+ "_label_" +i). Style.display = "None";
}
}
for (Var i=0;i<id;i++) {
This.copytoobject (this.styles[id],this.$ (this.divname+ "_td_" +i). Style);
}
for (; i<3;i++) {
This.copytoobject (this.styles[0],this.$ (this.divname+ "_td_" +i). Style);
}
}
passwordstrength.prototype.$ = function (s) {
return document.getElementById (s);
}
PasswordStrength.prototype.setSize = function (w,h) {
This.width = W;
This.height = h;
}
PasswordStrength.prototype.setMinLength = function (n) {
if (isNaN (n)) {
return;
}
n = number (n);
if (n>1) {
This.minlength = n;
}
}
PasswordStrength.prototype.setStyles = function () {
if (Arguments.length = = 0) {
return;
}
for (Var i=0;i<arguments.length && i < 4;i++) {
This.styles[i] = arguments[i];
}
This.copytostyle (This.selectedindex);
}
PasswordStrength.prototype.write = function (s) {
if (this.showed) {
return;
}
var n = (s = = ' string ')? this.$ (s): s;
if (typeof (N)!= "Object") {
return;
}
n.innerhtml = this.content;
This.copytostyle (This.selectedindex);
}
PasswordStrength.prototype.update = function (s) {
if (S.length < This.minlen) {
This.copytostyle (0);
Return
}
var ls =-1;
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--;
}
Switch (LS) {
Case 0:
This.copytostyle (1);
Break
Case 1:
This.copytostyle (2);
Break
Case 2:
This.copytostyle (3);
Break
Default
This.copytostyle (0);
}
}