zoukankan      html  css  js  c++  java
  • 密码强度验证

    <form name="form1" action="">
        密码:<input type="password" size="8" onkeyup="pwStrength(this.value)" onblur="pwStrength(this.value)">
        <br>
        密码强度:
        <table width="220px" border="1" cellspacing="0" cellpadding="1" bordercolor="#eeeeee" height="22px">
            <tr align="center" bgcolor="#f5f5f5">
                <td width="33%" id="strength_L"></td>
                <td width="33%" id="strength_M"></td>
                <td width="33%" id="strength_H"></td>
            </tr>
        </table>
    </form>
    function pwStrength(pwd) {
        O_color = "#eeeeee";
        L_color = "#FF0000";
        M_color = "#FF9900";
        H_color = "#33CC00";
        var level = 0, strength = "O";
        if (pwd == null || pwd == '') {
            strength = "O";
            Lcolor = Mcolor = Hcolor = O_color;
        }
        else {
            var mode = 0;
            if (pwd.length <= 4)
                mode = 0;
            else {
                for (i = 0; i < pwd.length; i++) {
                    var charMode, charCode;
                    charCode = pwd.charCodeAt(i);
                    // 判断输入密码的类型
                    if (charCode >= 48 && charCode <= 57) //数字  
                        charMode = 1;
                    else if (charCode >= 65 && charCode <= 90) //大写  
                        charMode = 2;
                    else if (charCode >= 97 && charCode <= 122) //小写  
                        charMode = 4;
                    else
                        charMode = 8;
                    mode |= charMode;
                }
                // 计算密码模式
                level = 0;
                for (i = 0; i < 4; i++) {
                    if (mode & 1)
                        level++;
                    mode >>>= 1;
                }
            }
            switch (level) {
                case 0:
                    strength = "O";
                    Lcolor = Mcolor = Hcolor = O_color;
                    break;
                case 1:
                    strength = "L";
                    Lcolor = L_color;
                    Mcolor = Hcolor = O_color;
                    break;
                case 2:
                    strength = "M";
                    Lcolor = Mcolor = M_color;
                    Hcolor = O_color;
                    break;
                default:
                    strength = "H";
                    Lcolor = Mcolor = Hcolor = H_color;
                    break;
            }
        }
        document.getElementById("strength_L").style.background = Lcolor;
        document.getElementById("strength_M").style.background = Mcolor;
        document.getElementById("strength_H").style.background = Hcolor;
        return strength;
    }
  • 相关阅读:
    重新认识数据库的链接查询
    mysql删除一张表中的重复数据
    mysql数据库里复制一张表的SQL,报错 (1786
    case when的使用场景。
    python:浅析python 中__name__ = '__main__' 的作用
    Group(), Groups(),& Groupdict() 用法
    python re模块findall()详解
    练习题(第二模块...模块...选择填空)
    subprocess模块 sys模块
    json,pickle,shelve模块,xml处理模块
  • 原文地址:https://www.cnblogs.com/MrZheng/p/7827008.html
Copyright © 2011-2022 走看看