用户输入密码强度检测js代码

2个月前 (03-04 20:41)阅读49回复0
大陆
大陆
  • 管理员
  • 发消息
  • 注册排名1
  • 经验值4189
  • 级别管理员
  • 主题837
  • 回复2
楼主

通过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=gb2312">
<meta name="keywords" content="武鸣人网站,武鸣信息网,武鸣本地网,武鸣信息资源平台,减肥,健身,励志,励志语录,js特效,网页特效,www.wuming.ren">
<meta name="description" content="欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。">
<title>用户输入密码强度检测js代码_武鸣人</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;}
#wuming_ren{float:left;margin:2px 0 0 20px;}
#wuming_ren span{float:left;width:50px;height:20px;color:#fff;overflow:hidden;background:#ccc;margin-right:2px;line-height:20px;text-align:center;}
#wuming_ren.s1 .active{background:#f30;}
#wuming_ren.s2 .active{background:#fc0;}
#wuming_ren.s3 .active{background:#cc0;}
#wuming_ren.s4 .active{background:#090;}
</style>
<script type="text/javascript">
window.onload = function ()
{//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
var oTips = document.getElementById("wuming_ren");
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 = "";
index && (aSpan[index - 1].className = "active", aSpan[index - 1].innerHTML = aStr[index - 1])
}
};
/** 强度规则
 + ------------------------------------------------------- +
1) 任何少于6个字符的组合,弱;任何字符数的同类字符组合,弱;
2) 任何字符数的两类字符组合,中;
3) 12位字符数以下的三类或四类字符组合,强;
4) 12位字符数以上的三类或四类字符组合,非常好。
 + ------------------------------------------------------- +
**/
//检测密码强度
function checkStrong(sValue)
{//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
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;
}
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
</script>
</head>
<body>
<a href="https://www.wuming.ren">武鸣人</a>,各种信息资源免费发布,分享励志语录经典短句,减肥健身常识,各种js特效代码。网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)<hr>
<!--欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。-->
<script type="text/javascript" src="https://www.wuming.ren/ad/tc.js"></script>
<script type="text/javascript" src="https://www.wuming.ren/ad/a.js"></script>
<input type="password" value="" maxlength="16">
<div id="wuming_ren"><span></span><span></span><span></span><span></span></div>
</body>
</html>


0
0
收藏0
回帖

用户输入密码强度检测js代码 期待您的回复!

取消
载入表情清单……
载入颜色清单……
插入网络图片

取消确定

图片上传中
编辑器信息
提示信息