Hi guys. im writing a program to check an input string (a password) for its level of security (strong, medium, weak). here is my code for the method:
public static int passwordType(String password) {
//0weak, 1medium, 2strong
int hasSix = 0;
int upper = 0;
int lower = 0;
int digit = 0;
//check for 6 chars
if (password.length() >= 6){
hasSix = 1;
}
//check for chars and numbers
for (int i=0; i<password.length(); i++){
upper = 0;
lower = 0;
digit = 0;
if (Character.isUpperCase(password.charAt(i))){
upper = 1;
}
if (Character.isLowerCase(password.charAt(i))){
lower = 1;
}
if (Character.isDigit(i)){
digit = 1;
}
}
//add the scores up and return the appropriate int (0,1,2)
int sum;
sum = upper + lower + digit + hasSix;
int result = 0;
if (sum == 4){
result= 2;}
if (sum == 3){
result= 1;}
if (sum <= 2){
result= 0;}
return result;
so as you can see this method should return a 0 for weak, 1 for medium and 2 for strong. however this doesnt work for some reason. it always returns 0. can anyone point me in the right direction? much thanks.