js密码强度
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>密码强度检测</title>
<style type="text/css">
body {
font: 12px/1.5 Arial;
}
input {
float: left;
font-size: 12px;
width: 150px;
font-family: arial;
border: 1px solid #ccc;
padding: 3px;
}
input.correct {
border: 1px solid green;
}
input.error {
border: 1px solid red;
}
#tips {
float: left;
margin: 2px 0 0 20px;
}
#tips span {
float: left;
width: 50px;
height: 20px;
color: #fff;
overflow: hidden;
background: #ccc;
margin-right: 2px;
line-height: 20px;
text-align: center;
}
#tips.s1 .active {
background: #f30;
}
#tips.s2 .active {
background: #fc0;
}
#tips.s3 .active {
background: #cc0;
}
#tips.s4 .active {
background: #090;
}
</style>
<script type="text/javascript">
window.onload = function() {
var oTips = document.getElementById("tips");
var oInput = document.getElementsByTagName("input")[0];
var aSpan = oTips.getElementsByTagName("span");
var aStr = ["弱", "中", "强", "非常好"];
var i = 0; oInput.onkeyup = oInput.onfocus = oInput.onblur = function() {
var index = checkStrong(this.value);
this.className = index ? "correct" : "error";
oTips.className = "s" + index;
for ( i = 0; i < aSpan.length; i++)
aSpan[i].className = aSpan[i].innerHTML = "";
if(index==4){
index && (aSpan[index - 1].className = "active", aSpan[index - 1].innerHTML = aStr[index - 1]);
index && (aSpan[index - 2].className = "active", aSpan[index - 2].innerHTML = aStr[index - 2]);
index && (aSpan[index - 3].className = "active", aSpan[index - 3].innerHTML = aStr[index - 3]);
index && (aSpan[index - 4].className = "active", aSpan[index - 4].innerHTML = aStr[index - 4]);
}else if(index==3){
index && (aSpan[index - 1].className = "active", aSpan[index - 1].innerHTML = aStr[index - 1]);
index && (aSpan[index - 2].className = "active", aSpan[index - 2].innerHTML = aStr[index - 2]);
index && (aSpan[index - 3].className = "active", aSpan[index - 3].innerHTML = aStr[index - 3]);
}else if(index==2){
index && (aSpan[index - 1].className = "active", aSpan[index - 1].innerHTML = aStr[index - 1]);
index && (aSpan[index - 2].className = "active", aSpan[index - 2].innerHTML = aStr[index - 2]);
}else if(index==1){
index && (aSpan[index - 1].className = "active", aSpan[index - 1].innerHTML = aStr[index - 1]);
} };
};
/** 强度规则
+ ------------------------------------------------------- +
1) 任何少于6个字符的组合,弱;任何字符数的同类字符组合,弱;
2) 任何字符数的两类字符组合,中;
3) 12位字符数以下的三类或四类字符组合,强;
4) 12位字符数以上的三类或四类字符组合,非常好。
+ ------------------------------------------------------- +
**/
//检测密码强度
function checkStrong(sValue) {
var modes = 0;
if (sValue.length < 6)
return modes;
if (/\d/.test(sValue))
modes++;
//数字
if (/[a-z]/.test(sValue))
modes++;
//小写
if (/[A-Z]/.test(sValue))
modes++;
//大写
if (/\W/.test(sValue))
modes++;
//特殊字符
switch (modes) {
case 1:
return 1;
break;
case 2:
return 2;
case 3:
case 4:
return sValue.length < 12 ? 3 : 4;
break;
}
}
</script>
</head>
<body>
<input type="password" value="" maxlength="16" />
<div id="tips">
<span></span><span></span><span></span><span></span>
</div>
</body>
</html>
js密码强度的更多相关文章
- JS密码强度检测
//校验密码强度---沒有匹配到以下級別就提示 function checkPassWord(value){ // 0: 表示第一个级别 1:表示第二个级别 2:表示第三个级别 // 3: 表示第四个 ...
- js密码强度校验
function AuthPasswd(string) { if(!string){ jQuery("#low").removeClass("org"); }) ...
- js实现密码强度
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- JS正则检测密码强度
今天遇到个需求,使用JS检测密码强度:密码长度最短为8,必须同时包含字母.数字.特殊符号. 代码如下: /* * 检测密码复杂度 */ function ...
- js判断密码强度
html代码: <form name="form1" action=""> 密码:<input type="password&quo ...
- js动态判断密码强度&&实用的 jQuery 代码片段
// 网上拷贝的代码,效果不太好需要自己调整<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &q ...
- 密码强度的js插件(完成)
效果如下图: 低:
- js 检验密码强度
html 代码如下: <!DOCTYPE HTML> <html lang="en"> <head> <meta charset=&quo ...
- js实现密码强度验证
<html> <head> <meta http-equiv="content-type" content="text/html" ...
随机推荐
- bjfu1281
思路挺简单的,但因为需要处理大数,所以就比较耗代码了. /* * Author : ben */ #include <cstdio> #include <cstdlib> #i ...
- VM虚拟机快照还原效果实现方式
===================================================默认"快照删除"行为:============================ ...
- log4net--帮助程序员将日志信息输出到各种目标(控制台、文件、数据库等)的工具
1. log4net库是Apache log4j框架在Microsoft .NET平台的实现,是一个帮助程序员将日志信息输出到各种目标(控制台.文件.数据库等)的工具. 2. Log4net的结构如下 ...
- mysql执行update报错1175解决方法
mysql执行update报错 update library set status=true where 1=1 Error Code: 1175. You are using safe update ...
- Android 相关
ADT 下载更新 http://www.oschina.net/question/1463998_220998 更改包名后,资源文件不更新 AndroidMainfast.xml文件,有package ...
- HW7.18
public class Solution { public static void main(String[] args) { int[][] m = {{1, 2}, {3, 4}, {5, 6} ...
- leetcode oj s_06
public class Solution { public static void main(String[] args) { String s = "PAYPALISHIRING&quo ...
- SQL时间第一期_获取系统年月日时分秒
select GETDATE() as '当前日期',DateName(year,GetDate()) as '年',DateName(month,GetDate()) as '月',DateName ...
- shell's glob
[shell's glob] basic glob example: range glob example: 参考: http://bash.cumulonim.biz/glob.html
- 查看80端口被占用的方法(IIS、apmserv、system)
端口如果被其他程序占用就不能正常启动,比如有时启动时会提示WEB启动失败,其实就是80 端口被占用了,而迅雷等下载软件恰恰就是占用了80端口,关掉就行了.但有时迅雷等都没有开 也启动不了,那就是别的东 ...