时间:2021-05-26
密码强度显示和中文强弱显示
复制代码 代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'a.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style type="text/css">
* {margin:0px;padding:0px;}
.J_PasswordStatus{padding-bottom:0px;height:18px;}
.status-bar{margin:0px;display:inline-block;width:80px;height:5px;padding:1px;border:1px solid #42BF26;background-color:white;vertical-align:middle;font-size:0;}
.status-bar span{background-color:#42BF26;height:5px;display:inline-block;}
</style>
</head>
<body>
<input type="password" id="pwd1" style="float:left;margin-top:5px;" onkeyup="checkPassword();"/>
<div id="p_PasswordStatus" class="J_PasswordStatus"
style="display: none; width: 300px;">
<span class="trigger">密码强度: </span>
<span class="status-bar" style="text-indent: 0px;">
<span style="line-height: 5px;"> </span>
</span>
<span class="status-result"></span>
</div>
</body>
</html>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
function checkPassword(){
var pwd = $("#pwd1").val();
gPasswdStatus(pwd,'p_PasswordStatus');
}
function gPasswdStatus(value,id){
var status = $("#"+id);
var result = $("#"+id).find(".status-result")[0];
var bar = $("#"+id).find(".status-bar span");
if (value === "") {
status.css("display","none");
} else {
var score = gCheckPassword(value);
bar.css("width",score + "%");
var resultDesp = gGetResultDesp(score);
result.innerHTML = resultDesp;
status.css("display","block");
}
}
/**
* 检验密码强度并返回得分
*
* @param {}
* password
* @return {Number}
*/
function gCheckPassword(password) {
var _score = 0;
if (!password) {
return 0
}
if (password.length <= 4) {
_score += 5
} else {
if (password.length >= 5 && password.length <= 7) {
_score += 10
} else {
if (password.length >= 8) {
_score += 25
}
}
}
var _UpperCount = (password.match(/[A-Z]/g) || []).length;
var _LowerCount = (password.match(/[a-z]/g) || []).length;
var _LowerUpperCount = _UpperCount + _LowerCount;
if (_UpperCount && _LowerCount) {
_score += 20
} else {
if (_UpperCount || _LowerCount) {
_score += 10
}
}
var _NumberCount = (password.match(/[\d]/g, "") || []).length;
if (_NumberCount > 0 && _NumberCount <= 2) {
_score += 10
} else {
if (_NumberCount >= 3) {
_score += 20
}
}
var _CharacterCount = (password.match(/[!@#$%^&*?_\.\-~]/g) || []).length;
if (_CharacterCount == 1) {
_score += 10
} else {
if (_CharacterCount > 1) {
_score += 25
}
}
if (_NumberCount && (_UpperCount && _LowerCount)
&& _CharacterCount) {
_score += 5
} else {
if (_NumberCount && _LowerUpperCount && _CharacterCount) {
_score += 3
} else {
if (_NumberCount && _LowerUpperCount) {
_score += 2
}
}
}
return _score
}
/**
* 根据密码强度得分返回密码强弱度中文提示
*
* @param {}
* score
* @return {String}
*/
function gGetResultDesp(score) {
if (score <= 5) {
return "\u592a\u77ed"
} else {
if (score > 5 && score < 20) {
return "\u5f31"
} else {
if (score >= 20 && score < 60) {
return "\u4e2d"
} else {
if (score >= 60) {
return "\u5f3a"
} else {
return ""
}
}
}
}
}
</script>
以上所述就是本文给大家分享的全部内容了,希望对大家熟练掌握javascript能够有所帮助。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了JavaScript动态检测密码强度原理及实现方法。分享给大家供大家参考,具体如下:在注册账户,设置密码时,会出现密码强度动态检测,网上看了一些帖
先看效果图:javascript密码强度校验代码,具体实现思路不多说了,请看下面代码和demo。第一种方法:/**密码安全程度*return:全部为字母或者数字
本文实例讲述了Python实现的密码强度检测器。分享给大家供大家参考,具体如下:密码强度密码强度如何量化呢?一个密码可以有以下几种类型:长度、大写字母、小写字母
JavaScript实现密码强度实时验证,供大家参考,具体内容如下在网络服务中,为了保证用户的私密信息足够安全,会要求用户输入具有一定安全级别的密码,这样可以更
一个用Javascript检测用户输入密码强度的效果代码,以下代码主要是从以下四个方面检测用户输入的密码的强度的,有兴趣的朋友可以自己添加或修改成自己想要的形式