密码强度显示和中文强弱显示
复制代码代码如下:
<! Doctype html public "-// w3c // dtd html 4.01 transisi // en">
<Html>
<head>
<base href = "<%= Basepath%>">
<Title> jsp 'a.jsp' halaman awal saya </iteme>
<meta http-equiv = "pragma" konten = "no-cache">
<meta http-equiv = "cache-control" content = "no-cache">
<meta http-equiv = "kedaluwarsa" konten = "0">
<meta http-equiv = "kata kunci" content = "kata kunci1, kata kunci2, kata kunci3">
<meta http-equiv = "description" content = "This is my Page">
<type style = "text/css">
* {margin: 0px; padding: 0px;}
.J_passwordstatus {padding-bottom: 0px; tinggi: 18px;}
.Status-bar {margin: 0px; display: inline-block; lebar: 80px; tinggi: 5px; padding: 1px; Border: 1px solid #42bf26; latar belakang-warna: putih; vertikal-align: tengah; font-ukuran: 0;}
.Status-Bar Span {latar belakang-warna:#42bf26; Tinggi: 5px; Tampilan: inline-block;}
</tyle>
</head>
<body>
<input type = "password" id = "pwd1" style = "float: left; margin-top: 5px;" onkeyup = "checkpassword ();"/>
<div id = "p_passwordstatus"
style = "display: none; lebar: 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>
<type skrip = "Teks/JavaScript">
function checkPassword () {
var pwd = $ ("#pwd1"). val ();
gpasswdstatus (pwd, 'p_passwordstatus');
}
fungsi gpasswdstatus (value, id) {
status var = $ ("#"+id);
var result = $ ("#"+id) .find (". Status-result") [0];
var bar = $ ("#"+id) .find (". Status-bar span");
if (value === "") {
status.css ("display", "none");
} kalau tidak {
var skor = gcheckpassword (nilai);
bar.css ("lebar", skor + "%");
var resultDesp = ggetResultDesp (skor);
result.innerhtml = resultDesp;
status.css ("display", "block");
}
}
/**
* 检验密码强度并返回得分
*
* @param {}
* Kata sandi
* @return {number}
*/
fungsi gcheckpassword (kata sandi) {
var _score = 0;
if (! password) {
kembali 0
}
if (password.length <= 4) {
_score += 5
} kalau tidak {
if (password.length> = 5 && password.length <= 7) {
_score += 10
} kalau tidak {
if (password.length> = 8) {
_score += 25
}
}
}
var _uppercount = (kata sandi.match (/[az]/g) || []). Panjang;
var _lowercount = (password.match (/[az]/g) || []). Panjang;
var _loweruppercount = _uppercount + _lowercount;
if (_uppercount && _lowercount) {
_score += 20
} kalau tidak {
if (_uppercount || _lowercount) {
_score += 10
}
}
var _numbercount = (kata sandi.match (/[/d]/g, "") || []). Panjang;
if (_numbercount> 0 && _numbercount <= 2) {
_score += 10
} kalau tidak {
if (_numbercount> = 3) {
_score += 20
}
}
var _charactercount = (kata sandi
if (_charactercount == 1) {
_score += 10
} kalau tidak {
if (_charactercount> 1) {
_score += 25
}
}
if (_numbercount && (_uppercount && _lowercount)
&& _charactercount) {
_score += 5
} kalau tidak {
if (_numbercount && _loweruppercount && _charactercount) {
_score += 3
} kalau tidak {
if (_numbercount && _loweruppercount) {
_score += 2
}
}
}
kembalikan _score
}
/**
* 根据密码强度得分返回密码强弱度中文提示
*
* @param {}
* skor
* @return {string}
*/
fungsi ggetResultDesp (skor) {
if (skor <= 5) {
return "/u592a/u77ed"
} kalau tidak {
if (skor> 5 && skor <20) {
return "/u5f31"
} kalau tidak {
if (skor> = 20 && skor <60) {
return "/u4e2d"
} kalau tidak {
if (skor> = 60) {
return "/u5f3a"
} kalau tidak {
kembali ""
}
}
}
}
}
</script>
以上所述就是本文给大家分享的全部内容了 , 希望对大家熟练掌握 JavaScript 能够有所帮助。