密码强度的js插件(完成)

效果如下图:

低:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXQAAABsCAIAAAD1895GAAAHtklEQVR4nO3dz07bWBuA8dzRLHIh2WQ7d3HuAc3a9/AtR+PFLLsDJ3YciosdqoJUoUKoWpUUAXIbbJ9ZnNixY0OcOOcDzPNTxYCTuH9GffSec9q087+//5U1vHv3rs7TAPwfRFEUhuHd3d3Nzc1sNpvNZjc3N3d3d2EYRlG06d129bt7XNQhLsAb9/xxAdBWzxkXAHgacQGgBXEBoAVxAaAFcQGgBXEBoAVxAaAFcQGgBXEBoMVu4mKKbleYKxc9o99dEkJ0C/qGt4ufAICXadu4mCupWJWlwzP6pexIKU1RdRVAa2wfl9zkYYp0bvGMft/w1MfFBZHLTPYa2gK0XYNlkSm6wkwHE1MIIcprnXyDcjNMIU0A2mjbuHhGvyvMtBim6KpNF8/zsofyuy59w8sVJZcZz+iz+wK0UcMN3cXWS7bGWQRkmZy+4aVXS9s0fcMjLkBbNZlcul21LnrkDMgUQohcXEo3YNsFaLEt42IahpdLRn6vNp8ScxkXQxQbZIjy4TWA9mi0obtJXFYnl8UJE8sioKWanRat+0Mu2VNK/chtCBMXoI0abuhWeXpyebw3ANpEQ1wAgLgA0IS4ANCCuADQgrgA0IK4ANCCuADQgrgA0IK4ANBiy7i8A9BezxyXnXz3AF4a4gJAC+ICQAviAkAL4gJAi1397v5ZRFyAt464ANCCuADQgrgA0IK4ANCCuADQgrgA0OJ1x6XT6TR5OYA4jqMoiuM4SZIoipIkub+/Pzs7+/Dhg+u6R0dHp6enP3/+VM9MkkR9rHNn4gK8aVkvHh4ekiS5urp6//79YDA4ODhwHMeyLMuyXNe9uLjInhnHcZ07ExfgTYtTSZJ8+/ZtOBxalnV0dHRxcfH9+/fLy0vf9y3Lsm378vJSTTfEBcB6almUJMmvX7+Oj48ty5pMJvf399kTwjD89OnT/v6+53mqLMQFwHrZgujHjx+2bY9Go+vrayllFEVRFD08PEgpf//+fXl5eX19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qTC6ljZjKuOwVl0JTs9mG7u7jEoUVty0sj4gLUMdKLB6bSrKnrSycNotLYUNXSrM07+w9c1zyt8vt7i5VVmaLX/bHEBe0R+G0KJtEsskljcrKTm8tFXsuveXnh1Lu9Qp7uodbxeWpH8GmcSmcFoVpnJaTy8oOL3EBajBF3/Aen1xM0RVm5cPVJ0VSVp4WqbPnw9yeS/b990rnR88wueRfyuQC7ETx4CedXNL/LgeX/G5McSFUY1mktl2klNNDOZ3KXvrlXkd2eosrL+EoulSpwsYucQE2sLLsyc8owpSmWN1cqTgjWhuXnpxKebiXfj6Ve2b65QuLS3H5kx9hmFyA2tJUCDO3V1s4OBJC9A1v+Wjamdzz6/8humxPN8tK+crzxSXtSDy/Xe7mFBZeUUVddvR/QkriAtSy9oy55rfU+mzUo++GzREXoAbisjniAtRAXDZHXABoQVwAaEFcAGhBXABoQVwAaEFcAGhBXABoQVwAaEFcAGixs7iU3ktQXVz5S2Br3qan8l95KL5dmBAr78Px1LsqA3g2K3H5DxpEIBmiyyxoAAAAAElFTkSuQmCC" alt="" width="260" height="75" />

中:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWoAAAByCAIAAAD1SAz2AAAKV0lEQVR4nO3dT0/bSBjH8b6jPeSFcPF138W8h2rPPvVdrI8c9gZJnASCSxKqglRQ+VMVlbZCUdrgePYwsT3j/5lCm1jfj6oWHHti2H1+eWYMzitZwhOdjvAyGwPX6aSEEB2D4wZlwwHYfUemV+kjXiYMspJwCFwnFyxSSk8UbQXQGlXxoXUPnoh7j8B1HDdQf683CC1IkmNID6DtyuNDrkMjbi48IYTIz0j0lNH6ECN8ALRReXwErtMRXpwJnuioxY8gCJKH9NUPxw20zNCCJHAdVkGANqrsPqRMlkCSmcg6ItJQcdwg3ppbLnHcgPgA2qq6++h01Oyl5HqKJ4QQWnyYSpZUAbREaXx4rhtooaCviuph4aXx4QozZVyRv9QLoD1qlk43iY9s97G+WsPkBWipuisvdT/0keySSwht6ZX4ANqodum0S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cg6g5Jcd1SYR/EO2uMrtI0TedX/flja7D6bX8kB7xGQQofr3aaO7DG0zfqbceTZpUnPBwFwXHaWKWosw1hpZbY3PAoOYHZW5Bma56mq5HZbM0fWyN1oNapIMXVijoZYQ4CFGU9EJaySVo4lhFCGKa/fjeLiXJ95e8oW4/GrB3br/zGgmQPU/h+WaUazda05PDotf5XpBQEyO0dyRU/juiGh6MgwEr9BzwFAeqr/gOeggA4KRQEgD4KAkAfBQGgj4IA0EdBAOijIAD0URAA+v4PrVz27eXO7BAAAAAASUVORK5CYII=" alt="" width="265" height="70" />

页面上需要绑定的id如下:

 <div class="passwordtishi f12">
<font class="c666">安全程度:</font>
<span id="strength_L">弱</span><span id="strength_M">中</span><span id="strength_H">强</span>
</div>

引用的js如下:

//密码强度弱中强变色js

//CharMode函数
//测试某个字符是属于哪一类.
function CharMode(iN) {
if (iN >= && iN <= ) //数字
return ;
if (iN >= && iN <= ) //大写字母
return ;
if (iN >= && iN <= ) //小写
return ;
else
return ; //特殊字符
}
//bitTotal函数
//计算出当前密码当中一共有多少种模式
function bitTotal(num) {
modes = ;
for (i = ; i < ; i++) {
if (num & ) modes++;
num >>>= ;
}
return modes;
}
//checkStrong函数
//返回密码的强度级别
function checkStrong(sPW) {
if (sPW.length <= )
return ; //密码太短
Modes = ;
for (i = ; i < sPW.length; i++) {
//测试每一个字符的类别并统计一共有多少种模式.
Modes |= CharMode(sPW.charCodeAt(i));
}
return bitTotal(Modes);
}
//pwStrength函数
//当用户放开键盘或密码输入框失去焦点时,根据不同的级别显示不同的颜色
function pwStrength(pwd) {
O_color = "#eeeeee";
L_color = "#FF0000";
M_color = "#FF9900";
H_color = "#33CC00";
if (pwd == null || pwd == '') {
Lcolor = Mcolor = Hcolor = O_color;
}
else {
S_level = checkStrong(pwd);
switch (S_level) {
case :
Lcolor = Mcolor = Hcolor = O_color;
case :
Lcolor = L_color;
Mcolor = Hcolor = O_color;
break;
case :
Lcolor = Mcolor = M_color;
Hcolor = O_color;
break;
default:
Lcolor = Mcolor = Hcolor = H_color;
}
}
document.getElementById("strength_L").style.background = Lcolor;
document.getElementById("strength_M").style.background = Mcolor;
document.getElementById("strength_H").style.background = Hcolor;
return;
}
上一篇:解决Android 6.0获取wifi Mac地址为02:00:00:00:00:00问题【转】


下一篇:SpringMVC、SpringMVC XML配置(纯XML方式)