检测密码强度

检测密码强度

function _getPasswordStrength(password) {
    return 0
        // if password bigger than 5 give 1 point
        + +(password.length > 5)
        // if password has both lower and uppercase characters give 1 point
        + +(/[a-z]/.test(password) && /[A-Z]/.test(password))
        // if password has at least one number and at least 1 other character give 1 point
        + +(/\d/.test(password) && /\D/.test(password))
        // if password has a combination of other characters and special character give 1 point
        + +(/[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/.test(password) && /\w/.test(password))
        // if password bigger than 12 give 1 point
        + +(password.length > 12);
};

console.log(_getPasswordStrength('asdfASDF12 341542$$@#!$'));
posted @ 2013-11-04 19:15  盗草人  阅读(336)  评论(0编辑  收藏  举报