Regular Expression for Password Strength Validation

后端 未结 6 1287
隐瞒了意图╮
隐瞒了意图╮ 2021-01-01 02:21

I have written a regular expression which could potentially be used for password strength validation:

^(?:([A-Z])*([a-z])*(\\d)*(\\W)*){8,12}$
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-01 02:59

    Check out this: http://jsfiddle.net/43tu58jf/

    function isSimpleStrongLevel(password){
        var stringsOptions = ['123456', '123abc', 'abc123', '654321', '012345', 'password', '123pass', 'pass123', '123456abc'];
        return stringsOptions.indexOf(password) != -1;
    }
    function getStrongLevel(password) {
        var level = 0;
        level += password.length > 6 ? 1 : 0;
        level += /[!@#$%^&*?_~]{2,}/.test(password) ? 1 : 0;
        level += /[a-z]{2,}/.test(password) ? 1 : 0;
        level += /[A-Z]{2,}/.test(password) ? 1 : 0;
        level += /[0-9]{2,}/.test(password) ? 1 : 0;
        return level;
    }
    
    var password = '123456';
    var isSimple = isSimpleStrongLevel(password);
    var level = getStrongLevel(password);
    console.log(isSimple, level);
    

提交回复
热议问题