检测密码强度

检测密码强度

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$$@#!$'));
原文地址:https://www.cnblogs.com/daocaowu/p/3407281.html