密码强度显示和中文强弱显示
复制代码代码如下:
<! doctype html public "-// w3c // dtd html 4.01 Transitional // en">
<html>
<head>
<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 = "Expires" content = "0">
<meta http-equiv = "الكلمات الرئيسية" content = "Keyword1 ، Keyword2 ، Keyword3">
<meta http-equiv = "description" content = "This is is my past">
<type type = "text/css">
* {margin: 0px ؛ padding: 0px ؛}
.j_passwordstatus {padding-bottom: 0px ؛ الارتفاع: 18px ؛}
.status-bar {margin: 0px ؛ display: inline block ؛ width: 80px ؛ quight: 5px ؛ padding: 1px ؛ border: 1px solid #42bf26 ؛ background-color: White ؛
.status-bar Span {background-color:#42bf26 ؛ الارتفاع: 5px ؛ العرض: inline-block ؛}
</style>
</head>
<body>
<type type = "password" id = "pwd1" style = "float: يسار ؛ الهامش: 5px ؛" OnKeyup = "checkPassword () ؛"/>
<div id = "p_passwordstatus"
style = "Display: None ؛ Width: 300px ؛">
<span> : </span>
<span style = "text-indent: 0px ؛">
<span style = "Line-Height: 5px ؛"> </span>
</span>
<span> </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 (القيمة ، معرف) {
var status = $ ("#"+id) ؛
var result = $ ("#"+id) .find (". status-result") [0] ؛
var bar = $ ("#"+id) .find (".
if (value === "") {
status.css ("display" ، "none") ؛
} آخر {
VAR SCORE = GCHECKPASTWORD (value) ؛
BAR.CSS ("العرض" ، النتيجة + "٪") ؛
var resultdesp = ggetResultDesp (Score) ؛
result.innerhtml = resultdesp ؛
status.css ("Display" ، "block") ؛
}
}
/**
* 检验密码强度并返回得分
*
* param {}
* كلمة المرور
* return {number}
*/
وظيفة gcheckpassword (كلمة المرور) {
var _score = 0 ؛
إذا (! كلمة المرور) {
إرجاع 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) || []). الطول ؛
var _lowercount = (password.match (/[az]/g) || []). الطول ؛
var _lowerupperCount = _upperCount + _lowerCount ؛
if (_uppercount && _lowercount) {
_score += 20
} آخر {
if (_uppercount || _lowerCount) {
_score += 10
}
}
var _numbercount = (password.match (/[/d]/g ، "") || []). الطول ؛
if (_numbercount> 0 && _numbercount <= 2) {
_score += 10
} آخر {
if (_numbercount> = 3) {
_score += 20
}
}
var _characterCount = (password.match (/budap!@$ ordd٪^^&*؟_/./- ~]/g) || []). الطول ؛
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 {}
* نتيجة
* @regurn {string}
*/
وظيفة ggetResultDesp (النتيجة) {
إذا (النتيجة <= 5) {
العودة "/u592a/u77ed"
} آخر {
if (Score> 5 && Score <20) {
العودة "/u5f31"
} آخر {
if (score> = 20 && score <60) {
العودة "/u4e2d"
} آخر {
if (score> = 60) {
العودة "/u5f3a"
} آخر {
يعود ""
}
}
}
}
}
</script>
以上所述就是本文给大家分享的全部内容了 , 希望对大家熟练掌握 javaScript 能够有所帮助。