Thursday, February 23, 2012

Simple password Strength checker




public class passwordStrength {

    private int checkPasswordStrength(String password) {
                int strengthPercentage=0;
        String[] partialRegexChecks = { ".*[a-z]+.*"// lower
                ".*[A-Z]+.*"// upper
                ".*[\\d]+.*"// digits
                ".*[@#$%]+.*" // symbols
        };


                    if (password.matches(partialRegexChecks[0])) {
                    strengthPercentage+=25;
            }
                    if (password.matches(partialRegexChecks[1])) {
                    strengthPercentage+=25;
            }
                    if (password.matches(partialRegexChecks[2])) {
                    strengthPercentage+=25;
            }
                    if (password.matches(partialRegexChecks[3])) {
                    strengthPercentage+=25;
            }


        return strengthPercentage;
    }

}

2 comments:

  1. Thanks for sharing!
    Do the work in a very clear and simple way.

    Chears,
    Tux

    ReplyDelete