My ; 更新日期:2025/12/28,互联网资源,高清电影,韩剧美剧,动漫资讯,游戏教程,序列号,破解版,注册机,绿色版,教程网,王者荣耀,SEO教程,网络教程,运营推广,下载中心,破解软件,游戏软件,网站源码,易语言源码,安卓软件,QQ软件,汉化版,无损音乐,MKV,WAV+CUE,FLAC,HQCD,MP3,SACD,DSD,抖音,4K高清,320k,度盘,百度云盘,蓝奏,微云盘,网盘,无广告纯净版,不限速下载,去广告,VIP解析,19" />
网络编程 
首页 > 网络编程 > 浏览文章

javascript实现密码强度显示

(编辑:jimmy 日期: 2025/12/28 浏览:3 次 )

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

复制代码 代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>My JSP 'a.jsp' starting page</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="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
        <style type="text/css">
    * {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>
  </head>
  <body>
    <input type="password"  id="pwd1" style="float:left;margin-top:5px;" onkeyup="checkPassword();"/>
        <div id="p_PasswordStatus" class="J_PasswordStatus"
            style="display: none; width: 300px;">
            <span class="trigger">密码强度: </span>
            <span class="status-bar" style="text-indent: 0px;">
            <span style="line-height: 5px;">&nbsp;&nbsp;</span>
            </span>
            <span class="status-result"></span>
        </div>
  </body>
</html>
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery-1.7.2.min.js"> <script type="text/javascript">
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(/[!@#$%^&*"\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 ""
            }
            }
        }
    }
 }
</script>

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

上一篇:自定义百度分享的分享按钮
下一篇:JavaScript通过元素索引号删除数组中对应元素的方法
一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 网站地图 SiteMap