密码强度显示和中文强弱显示
复制代码代码如下:
<! doctype html public "-// w3c // dtd html 4.01 transitional // en">
<html>
<head>
<base href = "<%= basepath%>">
<tite> หน้าเริ่มต้นของฉัน 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 = "คำหลัก" content = "keyword1, keyword2, keyword3">
<meta http-equiv = "คำอธิบาย" content = "นี่คือหน้าของฉัน">
<style type = "text/css">
* {margin: 0px; padding: 0px;}
.J_PasswordStatus {padding-bottom: 0px; ความสูง: 18px;}
.status-bar {margin: 0px; แสดง: inline-block; ความกว้าง: 80px; ความสูง: 5px; การเติม: 1px; ชายแดน: 1px ของแข็ง #42bf26; พื้นหลังสี: สีขาว; แนวตั้ง-แนว: กลาง;
.status-bar span {พื้นหลังสี:#42bf26; ความสูง: 5px; แสดง: inline-block;}
</style>
</head>
<body>
<อินพุต type = "รหัสผ่าน" id = "pwd1" style = "float: left; margin-top: 5px;" onkeyup = "checkpassword ();"/>
<div id = "p_passwordstatus"
style = "display: none; width: 300px;">
<span> 密码强度: </span>
<span style = "Indentent: 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 (value, id) {
สถานะ var = $ ("#"+id);
var result = $ ("#"+id) .find (". สถานะ,) [0];
var bar = $ ("#"+id) .find (". ช่วงเวลาสถานะบาร์");
if (value === "") {
status.css ("แสดง", "ไม่มี");
} อื่น {
คะแนน var = gCheckPassword (ค่า);
bar.css ("ความกว้าง", คะแนน + "%");
var resultDesp = ggetResultDesp (คะแนน);
result.innerhtml = resultDesp;
status.css ("แสดง", "block");
-
-
-
* 检验密码强度并返回得分
-
* @param {}
* รหัสผ่าน
* @return {number}
-
ฟังก์ชั่น 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) || []). ความยาว;
var _lowerCount = (password.match (/[az]/g) || []). ความยาว;
var _loweruppercount = _uppercount + _lowerCount;
ถ้า (_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 (/[th!@#$%^&ab*_/./- ~]/g) || []). ความยาว;
if (_characterCount == 1) {
_score += 10
} อื่น {
ถ้า (_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}
-
ฟังก์ชั่น ggetResultDesp (คะแนน) {
ถ้า (คะแนน <= 5) {
return "/u592a/u77ed"
} อื่น {
ถ้า (คะแนน> 5 && คะแนน <20) {
return "/u5f31"
} อื่น {
ถ้า (คะแนน> = 20 && คะแนน <60) {
return "/u4e2d"
} อื่น {
ถ้า (คะแนน> = 60) {
return "/u5f3a"
} อื่น {
กลับ ""
-
-
-
-
-
</script>
以上所述就是本文给大家分享的全部内容了, 希望对大家熟练掌握 JavaScript 能够有所帮助。