<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Dotnetcluster-Password strength checker</title>
<!-- http://dotnetcluster.blogspot.in -->
<script language="javascript" type="text/javascript">
function pwdStrength(password)
{
var desc = new Array();
desc[0] = "<font color='red'>Very Weak</font>";
desc[1] = "<font color='red'> Weak</font>";
desc[2] = "<font color='blue'>Better</font>";
desc[3] = "<font color='blue'>Strong</font>";
desc[4] = "<font color='green'>Strongest</font>";
var score = 0;
//if password bigger than 6 give 1 point
if (password.length > 3) score++;
//if password has both lower and uppercase characters give 1 point
if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) score++;
//if password has at least one number give 1 point
if (password.match(/\d+/)) score++;
//if password has at least one special caracther give 1 point
if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) score++;
//if password bigger than 12 give another 1 point
if (password.length > 8) score++;
document.getElementById("pwdDescription").innerHTML = desc[score];
document.getElementById("pwdStrength").className = "strength" + score;
}
</script>
</head>
<body>
<table>
<tr>
<td>
Password<input type="password" name="pass" id="pass" onkeyup="pwdStrength(this.value)" />
</td>
<td>
<div id="pwdDescription" style="color: pink"">
</div>
</td>
</tr>
</table>
</body>
</html>

No comments:
Post a Comment