密码强度判断,弱中强

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title></title>
 
    <scriptlanguage="javascript"type="text/javascript">
        function checkstr(str)
        {
            if (str >= 48 && str <= 57)//数字
            {
                return 1;
            }
            else if (str >= 65 && str <= 90)//大写字母
            {
                return 2;
            }
            else if (str >= 97 && str <= 122)//小写字母
            {
                return 3;
            }
            else//特殊字符
            {
                return 4;
            }
        }
 
        function checkl(string)
        {
            n = false;
            s = false;
            t = false;
            l_num = 0;
            if(string.length <= 0){
                 l_num = 0;
            }
            if (string.length < 6&& string.length > 0)
            {
                l_num = 1;
            }
            else
            {
                for (i = 0; i < string.length; i++)
                {
                    asc= checkstr(string.charCodeAt(i));
 
                    if (asc == 1 && n == false)
                    { l_num += 1; n= true; }
 
                    if ((asc == 2 || asc == 3) && s == false)
                    { l_num += 1; s= true; }
 
                    if (asc == 4 && t == false)
                    { l_num += 1; t= true; }
                }
            }
            return l_num;
        }
 
        function checklevel(psw)
        {
            color= "#ededed";
            color_l= "#ff0000";
            color_m= "#ff9900";
            color_h= "#33cc00";
 
             
            if (psw == null || psw == '')
            {
                lcor= color;
                mcor= color;
                hcor= color;
            }
            else
            {
                thelev= checkl(psw)
                switch (thelev)
                {
                     case 0:
                        lcor= hcor= mcor= color;
                        break;
                    case 1:
                        lcor= color_l;
                        hcor= mcor= color;
                        break;
                    case 2:
                        mcor= lcor= color_m;
                        hcor= color;
                        break;
                    case 3:
                        hcor= mcor= lcor= color_h;
                        break;
                    default:
                        lcor= mcor= hcor= color;
                }
            }
            document.getElementById("strength_L").style.background= lcor;
            document.getElementById("strength_M").style.background= mcor;
            document.getElementById("strength_H").style.background= hcor;
        }
 
    </script>
 
</head>
<body>
    <form>
    密码:
    <inputtype="password"size="10"onkeyup="checklevel(this.value)"onchange="checklevel(this.value)"/>
    <br/><br/><br/>
    强度:
    <tablewidth="210"cellspacing="1"cellpadding="0"bordercolor="#cccccc"height="9">
        <tralign="center"bgcolor="#eeeeee">
            <tdwidth="33%"height="5"id="strength_L">
            </td>
            <tdwidth="33%"id="strength_M">
            </td>
            <tdwidth="33%"id="strength_H">
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值