Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Java by sdgs ( 6 years ago )
import java.util.Scanner; //Needed for the Scanner 

public class Practice {
    public static void main(String[] args) {
        
        String password = "";
        boolean hasDigit = false;
        boolean hasUpperCase = false;
        boolean hasLowerCase = false;
        boolean hasSixChars = false;
        boolean isValid = false;

        Scanner Keyboard = new Scanner(System.in);

        do {
            hasDigit = false;
            hasUpperCase = false;
            hasLowerCase = false;
            hasSixChars = false;
            isValid = false;

            System.out.print("What do you want your password to be?: ");
            password = Keyboard.nextLine();

            if (password.length() >= 6) {
                hasSixChars = true;
            }
            else System.out.println("Your password must contain 6 or more character.");

            for (int i = 0; i < password.length(); i++) {
                password.charAt(i);
                if (Character.isDigit(i)) {
                    hasDigit = true;
                }
                if (Character.isUpperCase(i)) {
                    hasUpperCase = true;
                }
                if (Character.isLowerCase(i)) {
                    hasLowerCase = true;
                }
            }

            if (hasDigit==true && hasUpperCase==true && hasLowerCase==true && hasSixChars==true) {
                isValid = true;
                System.out.println("Your password is valid!");
            }
            else {
                System.out.println("Your password is invalid!");
            }
        } while (isValid == true);
    }
}

 

Revise this Paste

Your Name: Code Language: