html中显示密码强度的代码,javascript实现密码强度显示

密码强度显示和中文强弱显示

My JSP 'a.jsp' starting page

* {margin:0px;padding: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="display: none; width: 300px;">

密码强度:

function checkPassword(){

var pwd = $("#pwd1").val();

gPasswdStatus(pwd,'p_PasswordStatus');

}

function gPasswdStatus(value,id){

var status = $("#"+id);

var result = $("#"+id).find(".status-result")[0];

var bar = $("#"+id).find(".status-bar span");

if (value === "") {

status.css("display","none");

} else {

var score = gCheckPassword(value);

bar.css("width",score + "%");

var resultDesp = gGetResultDesp(score);

result.innerHTML = resultDesp;

status.css("display","block");

}

}

/**

* 检验密码强度并返回得分

*

* @param {}

*            password

* @return {Number}

*/

function gCheckPassword(password) {

var _score = 0;

if (!password) {

return 0

}

if (password.length <= 4) {

_score += 5

} else {

if (password.length >= 5 && password.length <= 7) {

_score += 10

} else {

if (password.length >= 8) {

_score += 25

}

}

}

var _UpperCount = (password.match(/[A-Z]/g) || []).length;

var _LowerCount = (password.match(/[a-z]/g) || []).length;

var _LowerUpperCount = _UpperCount + _LowerCount;

if (_UpperCount && _LowerCount) {

_score += 20

} else {

if (_UpperCount || _LowerCount) {

_score += 10

}

}

var _NumberCount = (password.match(/[\d]/g, "") || []).length;

if (_NumberCount > 0 && _NumberCount <= 2) {

_score += 10

} else {

if (_NumberCount >= 3) {

_score += 20

}

}

var _CharacterCount = (password.match(/[!@#$%^&*?_\.\-~]/g) || []).length;

if (_CharacterCount == 1) {

_score += 10

} else {

if (_CharacterCount > 1) {

_score += 25

}

}

if (_NumberCount && (_UpperCount && _LowerCount)

&& _CharacterCount) {

_score += 5

} else {

if (_NumberCount && _LowerUpperCount && _CharacterCount) {

_score += 3

} else {

if (_NumberCount && _LowerUpperCount) {

_score += 2

}

}

}

return _score

}

/**

* 根据密码强度得分返回密码强弱度中文提示

*

* @param {}

*            score

* @return {String}

*/

function gGetResultDesp(score) {

if (score <= 5) {

return "\u592a\u77ed"

} else {

if (score > 5 && score < 20) {

return "\u5f31"

} else {

if (score >= 20 && score < 60) {

return "\u4e2d"

} else {

if (score >= 60) {

return "\u5f3a"

} else {

return ""

}

}

}

}

}

以上所述就是本文给大家分享的全部内容了,希望对大家熟练掌握javascript能够有所帮助。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值