javascript 检测密码强度 美化版
模仿美团的美化
<!DOCTYPE>
<head runat="server">
<title></title>
<link rel="stylesheet" type="text/css" href="mima.css">
<script src="jquery-1.9.0.min.js"></script>
<script src="MeForCopy.js"></script>
</head>
<body>
<form name="form1" action="">
<input type="password" size="10" id="password">
<br>
<div class="pw-strength">
<div id="J-pw-strength__bar" class="pw-strength__bar"></div>
<div class="pw-strength__letter">
<span class="pw-strength__label">L</span>
<span class="pw-strength__label">M</span>
<span class="pw-strength__label pw-strength__label--noborder">H</span>
</div>
</div>
<div id="msg"></div>
</form>
</body>
</html>
JS
$(function() {
$("#password").blur(function(event) {
/* Act on the event */
var psw = $(this).val(); //okay
pwStrength(psw);
});
$("#password").keyup(function(event) {
/* Act on the event */
var psw = $(this).val(); //okay
pwStrength(psw);
});
});
function pwStrength(psw) {
if (psw == '') {
$("#msg").text('no');
$(".pw-strength__bar").removeAttr('class').addClass('pw-strength__bar');
} else {
S_level = checkStrong(psw);
switch (S_level) {
case 0:
$("#msg").text('no');
$(".pw-strength__bar").removeAttr('class').addClass('pw-strength__bar');
case 1:
$("#msg").text('weak');
$(".pw-strength__bar").removeAttr('class').addClass('pw-strength__bar').addClass('pw-strength__bar--weak');
break;
case 2:
$("#msg").text('normal');
$(".pw-strength__bar").removeAttr('class').addClass('pw-strength__bar').addClass('pw-strength__bar--normal');
break;
default:
$("#msg").text('Strong');
$(".pw-strength__bar").removeAttr('class').addClass('pw-strength__bar').addClass('pw-strength__bar--strong');
}
}
}
function checkStrong(sPW) {
if (sPW.length <= 4) {
return 0; //密码太短
}
Modes = 0;
for (i = 0; i < sPW.length; i++) {
//测试每一个字符的类别并统计一共有多少种模式.
Modes |= CharMode(sPW.charCodeAt(i));
}
return bitTotal(Modes);
}
//CharMode函数
//测试某个字符是属于哪一类.
function CharMode(iN) {
if (iN >= 48 && iN <= 57) //数字
return 1;
if (iN >= 65 && iN <= 90) //大写字母
return 2;
if (iN >= 97 && iN <= 122) //小写
return 4;
else
return 8; //特殊字符
}
//bitTotal函数
//计算出当前密码当中一共有多少种模式
function bitTotal(num) {
modes = 0;
for (i = 0; i < 4; i++) {
if (num & 1) modes++;
num >>>= 1;
}
return modes;
}
CSS
.pw-strength {
background: none repeat scroll 0 0 #C9E0DD;
left: 80px;
position: absolute;
top: 45px;
width: 234px;
}
.pw-strength__bar {
background: none repeat scroll 0 0 #C9E0DD;
height: 16px;
overflow: hidden;
width:;
-moz-transition: all 0.4s linear 0s;
transition: all .4s linear;
-webkit-transition: all .4s linear;
-moz-transition: all .4s linear;
-o-transition: all .4s linear;
}
.pw-strength__letter {
left:;
position: absolute;
top:;
}
.pw-strength__bar--normal {
background: none repeat scroll 0 0 #F1D93A;
width: 154px;
}
.pw-strength__bar--weak {
background: none repeat scroll 0 0 #EA9292;
width: 76px;
}
.pw-strength__bar--strong {
background: none repeat scroll 0 0 #5AAC47;
width: 232px;
}
.pw-strength__label {
border-right: 2px solid #FFFFFF;
color: #FFFFFF;
display: block;
float: left;
font-size: 12px;
height: 16px;
line-height: 16px;
text-align: center;
width: 76px;
}
javascript 检测密码强度 美化版的更多相关文章
- javascript 检测密码强度
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JS正则检测密码强度
今天遇到个需求,使用JS检测密码强度:密码长度最短为8,必须同时包含字母.数字.特殊符号. 代码如下: /* * 检测密码复杂度 */ function ...
- JavaScript判断密码强度
以下是代码: <html> <head> <title>JS判断密码强度</title> <script language=javascript& ...
- JavaScript验证密码强度
JavaScript的方法: <script type="text/javascript"> window.onload = function () { documen ...
- js检测密码强度
<script> function AuthPasswd(string) { if(string.length >=6) { if(/[a-zA-Z]+/.t ...
- [No0000CE]检测非空格字符作为密码的密码强度
Regex.Replace(pwd, "^(?:([a-z])|([A-Z])|([0-9])|(.)){6,}|(.)+$", "$1$2$3$4$5").L ...
- js动态判断密码强度&&实用的 jQuery 代码片段
// 网上拷贝的代码,效果不太好需要自己调整<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &q ...
- js密码强度
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 密码强度应用(js)
<!-- 密码强度div --> <div id="tips" class="help-block"> <b class=&quo ...
随机推荐
- POJ 1743 Musical Theme(后缀数组+二分答案)
[题目链接] http://poj.org/problem?id=1743 [题目大意] 给出一首曲子的曲谱,上面的音符用不大于88的数字表示, 现在请你确定它主旋律的长度,主旋律指的是出现超过一次, ...
- 利用BP神经网络预测水道浅滩演变
论文 <基于现代技术的河道浅滩演变研究> 利用BP神经网络来预测浅滩演变 BP输出因子:浅滩的年平均淤积厚度以及浅滩上最小水深,是反映浅滩变化的两个基本指标,是确定浅滩航道尺度能否满足航行 ...
- Java图形化界面设计——布局管理器之BorderLayout(边界布局)
- Yii2简单纪要
网上经常拿Yii来类比ROR,从MVC角度,使用体验及代码风格上确实有很多相似的地方.不过看配置文件发现Yii2不止是受rails的影响,同样有不少spring的影子,最明显的就是配置文件中很多IOC ...
- Python输出中文乱码问题
//建立一个文件test.txt,文件格式用ANSI,内容为: //abc中文 //用python来读取 # coding=gbk print open("Test.txt").r ...
- 【Tomcat】使用Eclipse发布项目时,项目启动路径错误。
这种情况下,,通常会去C:\User\[USERNAME]\或者Tomcat路径下面的一个temp文件夹里面找项目文件,由此出现报错. 这时候解决方法为: 双击Eclipse的Servers里面的to ...
- If the server requires more time, try increasing the timeout in the server editor
双击服务器,在overview下的Timeouts中的Start选项,改成10000或者较大就可以了.防止服务器自启动频繁.
- vs2013出现ISO C++ conformant解决办法
出现:错误 1 error C4996: 'strnset': The POSIX name for this item is deprecated. Instead, use the I ...
- (转)原子操作 Interlocked系列函数
上一篇<多线程第一次亲密接触 CreateThread与_beginthreadex本质区别>中讲到一个多线程报数功能.为了描述方便和代码简洁起见,我们可以只输出最后的报数结果来观察程序是 ...
- Struts2,Spring,Hibernate三大框架的整合(SSH)
一.搭建struts2 1).导入struts2 jar包 2).编写web.xml 3).编写jsp页面 4).创建action类,action类要继承ActionSupport类 5).创建str ...