规则如下(分四个等级,等级超高强度越高):
0. 密码为空
1. 密码长度小于六位.或者密码只有一种组合
2.密码长度大于五位, 且有两种组合.
3. 密码长度大于五位, 且有三种组合.
4. 密码长度大于五位, 且有四种组合.
四种组合指 数字,小写字母,大写字母,其它字符
源代码如下:
function EvaluatePassword(word)
{
if (word == "")
{
return 0;
}
else if (word.length < 6)
{
return 1;
}
else
{
return word.match(/[a-z](?![^a-z]*[a-z])|[A-Z](?![^A-Z]*[A-Z])|\d(?![^\d]*\d)|[^a-zA-Z\d](?![a-zA-Z\d]*[^a-zA-Z\d])/g).length;
}
}
{
if (word == "")
{
return 0;
}
else if (word.length < 6)
{
return 1;
}
else
{
return word.match(/[a-z](?![^a-z]*[a-z])|[A-Z](?![^A-Z]*[A-Z])|\d(?![^\d]*\d)|[^a-zA-Z\d](?![a-zA-Z\d]*[^a-zA-Z\d])/g).length;
}
}
测试代码:
<script language="JavaScript">
function EvaluatePassword(word)
{
if (word == "")
{
return 0;
}
else if (word.length < 6)
{
return 1;
}
else
{
return word.match(/[a-z](?![^a-z]*[a-z])|[A-Z](?![^A-Z]*[A-Z])|\d(?![^\d]*\d)|[^a-zA-Z\d](?![a-zA-Z\d]*[^a-zA-Z\d])/g).length;
}
}
var test = new Array("", "a1_", "abcdef", "abcde123", "ads23%", "aA1B2^&2");
for(var i in test)
{
document.write(test[i] + " 的密码强度为" + EvaluatePassword(test[i]) + "<br>");
}
</script>
function EvaluatePassword(word)
{
if (word == "")
{
return 0;
}
else if (word.length < 6)
{
return 1;
}
else
{
return word.match(/[a-z](?![^a-z]*[a-z])|[A-Z](?![^A-Z]*[A-Z])|\d(?![^\d]*\d)|[^a-zA-Z\d](?![a-zA-Z\d]*[^a-zA-Z\d])/g).length;
}
}
var test = new Array("", "a1_", "abcdef", "abcde123", "ads23%", "aA1B2^&2");
for(var i in test)
{
document.write(test[i] + " 的密码强度为" + EvaluatePassword(test[i]) + "<br>");
}
</script>