密码强度显示和中文强弱显示
复制代码代码如下:
<! Doctype html public "-// w3c // dtd html 4.01 Transitional // en">
<html>
<голова>
<base href = "<%= basepath%>">
<title> my jsp 'a.jsp' начальная страница </title>
<meta http-equiv = "pragma" content = "no-cache">
<meta http-equiv = "cache-control" content = "no-cache">
<meta http-equiv = "истекает" content = "0">
<meta http-equiv = "Keywords" content = "Keyword1, Keyword2, Keyword3">
<meta http-equiv = "description" content = "Это моя страница">
<стиль типа = "text/css">
* {margin: 0px; падки: 0px;}
.J_passwordstatus {Padding-Bottom: 0px; высота: 18px;}
.Status-bar {Margin: 0px; Display: Inline Block; ширина: 80px; высота: 5px; накладка: 1px; граница: 1px sold #42bf26; фоновый цвет: белый; вертикальный анкет: средний; размер font: 0;}
.status-bar span {foangy-color:#42bf26; Высота: 5px; дисплей: inline block;}
</style>
</head>
<тело>
<input type = "password" id = "pwd1" style = "float: left; маржа-op: 5px;" OnKeyUp = "CheckPassword ();"/>
<div id = "p_passwordstatus"
Style = "Display: нет; ширина: 300px;">
<pran> 密码强度 : </span>
<span style = "text-indent: 0px;">
<span style = "line-height: 5px;"> </span>
</span>
<pran> </span>
</div>
</body>
</html>
<script type = "text/javascript" src = "jquery-1.7.2.min.js"> </script>
<script type = "text/javascript">
функция CheckPassWord () {
var pwd = $ ("#pwd1"). val ();
gpasswdstatus (pwd, 'p_passwordstatus');
}
функция gpasswdstatus (значение, id) {
var status = $ ("#"+id);
var result = $ ("#"+id) .find ("..-result") [0];
var bar = $ ("#"+id) .find (".. Статус-бар Span");
if (value === "") {
status.css ("display", "none");
} еще {
var score = gcheckpassword (значение);
bar.css («ширина», оценка + "%");
var resultDesp = ggetResultdesp (оценка);
result.innerhtml = resultDesp;
status.css ("display", "block");
}
}
/**
* 检验密码强度并返回得分
*
* @param {}
* пароль
* @return {номер}
*/
Функция gcheckpassword (пароль) {
var _score = 0;
if (! пароль) {
возврат 0
}
if (password.length <= 4) {
_score += 5
} еще {
if (password.length> = 5 && password.length <= 7) {
_score += 10
} еще {
if (password.length> = 8) {
_score += 25
}
}
}
var _uppercount = (password.match (/[az]/g) || []). Length;
var _lowercount = (password.match (/[az]/g) || []). Length;
var _loweruppercount = _uppercount + _lowercount;
if (_uppercount && _lowercount) {
_score += 20
} еще {
if (_uppercount || _lowercount) {
_score += 10
}
}
var _numberCount = (password.match (/[/d]/g, "") || []). Length;
if (_numberCount> 0 && _numberCount <= 2) {
_score += 10
} еще {
if (_numberCount> = 3) {
_score += 20
}
}
var _CharacterCount = (password.match (/^@#$%^^&*?_/./- ~]/g) || []). Length;
if (_charactercount == 1) {
_score += 10
} еще {
if (_charactercount> 1) {
_score += 25
}
}
if (_numberCount && (_Uppercount && _lowerCount)
&& _CharacterCount) {
_score += 5
} еще {
if (_numbercount && _loweruppercount && _charactercount) {
_score += 3
} еще {
if (_numbercount && _loweruppercount) {
_score += 2
}
}
}
вернуть _score
}
/**
* 根据密码强度得分返回密码强弱度中文提示
*
* @param {}
* счет
* @return {String}
*/
function ggetresultdesp (оценка) {
if (оценка <= 5) {
возврат "/u592a/u77ed"
} еще {
if (оценка> 5 && оценка <20) {
вернуть "/u5f31"
} еще {
if (score> = 20 && оценка <60) {
вернуть "/u4e2d"
} еще {
if (оценка> = 60) {
вернуть "/u5f3a"
} еще {
возвращаться ""
}
}
}
}
}
</script>
以上所述就是本文给大家分享的全部内容了 , 希望对大家熟练掌握 JavaScript 能够有所帮助。