What is the best way to check the strength of a password?

后端 未结 15 1266
孤独总比滥情好
孤独总比滥情好 2020-12-02 10:41

What is the best way of ensuring that a user supplied password is a strong password in a registration or change password form?

One idea I had (in python)

<         


        
15条回答
  •  旧巷少年郎
    2020-12-02 11:11

    Well this is what I use:

       var getStrength = function (passwd) {
        intScore = 0;
        intScore = (intScore + passwd.length);
        if (passwd.match(/[a-z]/)) {
            intScore = (intScore + 1);
        }
        if (passwd.match(/[A-Z]/)) {
            intScore = (intScore + 5);
        }
        if (passwd.match(/\d+/)) {
            intScore = (intScore + 5);
        }
        if (passwd.match(/(\d.*\d)/)) {
            intScore = (intScore + 5);
        }
        if (passwd.match(/[!,@#$%^&*?_~]/)) {
            intScore = (intScore + 5);
        }
        if (passwd.match(/([!,@#$%^&*?_~].*[!,@#$%^&*?_~])/)) {
            intScore = (intScore + 5);
        }
        if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/)) {
            intScore = (intScore + 2);
        }
        if (passwd.match(/\d/) && passwd.match(/\D/)) {
            intScore = (intScore + 2);
        }
        if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/) && passwd.match(/\d/) && passwd.match(/[!,@#$%^&*?_~]/)) {
            intScore = (intScore + 2);
        }
        return intScore;
    } 
    

提交回复
热议问题