密码强度显示和中文强弱显示
复制代码代码如下:
<!doctype html public " - // w3c // dtd html 4.01 transitional // en">
<html>
<head>
<base href = "<%= basepath%>">
<Title>私のjsp 'a.jsp'開始ページ</title>
<メタhttp-equiv = "pragma" content = "no-cache">
<Meta http-equiv = "cache-control" content = "no-cache">
<メタhttp-equiv = "expires" content = "0">
<meta http-equiv = "keywords" content = "keyword2、keyword3">
<メタhttp-equiv = "description" content = "これは私のページ">
<style type = "text/css">
* {マージン:0px;パディング: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"
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"> </scrip>
<script type = "text/javascript">
関数checkpassword(){
var pwd = $( "#pwd1")。val();
gpasswdstatus(pwd、 'p_passwordstatus');
}
関数gpasswdstatus(value、id){
var status = $( "#"+id);
var result = $( "#"+id).find( "。status-result")[0];
var bar = $( "#"+id).find( "。ステータスバースパン");
if(value === ""){
status.css( "display"、 "none");
} それ以外 {
var score = gcheckpassword(value);
bar.css( "width"、score + "%");
var resultDesp = ggetResultDesp(score);
result.innerhtml = resultDesp;
status.css( "display"、 "block");
}
}
/**
*检验密码强度并返回得分
*
* @param {}
*パスワード
* @return {number}
*/
関数gcheckpassword(パスワード){
var _score = 0;
if(!password){
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)/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 getresultdesp(score){
if(score <= 5){
return "/u592a/u77ed"
} それ以外 {
if(スコア> 5 &&スコア<20){
return "/u5f31"
} それ以外 {
if(score> = 20 && score <60){
return "/u4e2d"
} それ以外 {
if(score> = 60){
return "/u5f3a"
} それ以外 {
戻る ""
}
}
}
}
}
</script>
以上所述就是本文给大家分享的全部内容了、希望对大家熟练掌握javascript能够有所帮助。