PasswordChecker Java program
Question
I am currently compiling a PasswordChecker Java program.
The program has three rules:
1. must have 3 characters.
2. must have at least 1 UPPERCASE letter.
3. must have at least 1 lowercase letter.
The program executes the first system.out.print but the program fails when I put in 3 characters w/1uppercase & 1digit. I can’t see where I am going wrong. Please assist!
————————————————————————————————————————————-
package passwordchecker;
import java.util.Scanner;
public class PasswordChecker {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String password; //Initiates string and boolean
int passwordLength = 0;
boolean upperCheck = false;
boolean digitCheck = false;
boolean lengthCheck = false;
System.out.println(“Please enter a 3 character password with at least one UPPERCASE letter and one digit: “);
password = scnr.nextLine();
if (password.length()== 3){
lengthCheck = true;
if (Character.isUpperCase(0)){
upperCheck = true;
}
if (Character.isUpperCase(1)){
upperCheck = true;
}
if (Character.isUpperCase(2)){
upperCheck = true;
}
if (Character.isDigit(password.charAt(0))){
digitCheck = true;
}
if (Character.isDigit(password.charAt(1))){
digitCheck = true;
}
if (Character.isDigit(password.charAt(2))){
digitCheck = true;
}
}
if (lengthCheck == true && upperCheck == true && digitCheck == true){
System.out.println(“The password provided is valid.”);
}
else {
System.out.println(“The password provided is invalid. Please try again.”);
}
}
}