JavaScript判断密码强度

输入密码:

密码强度:

(function ($) {
    var pswstrength = function () { }
    pswstrength.prototype = {
        constructor: pswstrength,
        CharMode: function (iN) {
            if (iN >= 48 && iN <= 57) return 1;
            if (iN >= 65 && iN <= 90) return 2;
            if (iN >= 97 && iN <= 122) return 4;
            else return 8;
        },
        bitTotal: function (num) {
            modes = 0;
            for (i = 0; i < 4; i++) {
                if (num & 1) modes++;
                num >>>= 1;
            }
            return modes;
        },
        check: function (sPW) {
            if (sPW.length < 7)
                return 0;
            Modes = 0;
            for (i = 0; i < sPW.length; i++) {
                Modes |= this.CharMode(sPW.charCodeAt(i));
            }
            return this.bitTotal(Modes);
        }
    }

    if (typeof $.pswstrength == 'undefined' || $.pswstrength == null) {
        $.pswstrength = new pswstrength();
    }
})(jQuery)

$(function () {
    $("input").keyup(function () {
        $("span").removeClass("span-important span-warning span-success");
        switch ($.pswstrength.check($(this).val())) {
            case 2:
                $("span").addClass("span-success");
                break;
            case 1:
                $("span:lt(2)").addClass("span-warning");
                break;
            case 0:
                $("span:lt(1)").addClass("span-important");
                break;
        }
    });
});