#Java loop help for a school exercise

3 messages · Page 1 of 1 (latest)

worn isle
#

Hey can some1 help me with a current project in my class, its a password cracked so the start of it is like ```java
private static String ALLOWED_CHARS = "ABCabc012!";

public static void main(String[] args) {

    StringBuilder password = new StringBuilder();
    Random random = new Random();

    for (int i = 0; i < 5; i++) {
        int index = random.nextInt(ALLOWED_CHARS.length());
        password.append(ALLOWED_CHARS.charAt(index));
    }

so it should create a random password in this case with 5 chars long with only "ABCabc012!" but now i need crack it and i have no clue how to start a correct nested loop for this to try every possible combination.
worn isle
#
        for (int i = 0; i < ALLOWED_CHARS.length(); i++) {
            for (int j = 0; j < ALLOWED_CHARS.length(); j++) {
                for (int k = 0; k < ALLOWED_CHARS.length(); k++) {
                    for (int l = 0; l < ALLOWED_CHARS.length(); l++) {
                        for (int m = 0; m < ALLOWED_CHARS.length(); m++) {
                            String possiblePassword = "" + ALLOWED_CHARS.charAt(i) + ALLOWED_CHARS.charAt(j) + ALLOWED_CHARS.charAt(k) + ALLOWED_CHARS.charAt(l) + ALLOWED_CHARS.charAt(m);
                            // check if possiblePassword matches the actual password
                        }
                    }
                }
            }
        }

So now i use this but i have no clue how to stop it when he guessed the right password i thought mabye with a boolean or with string.equals(string). Maybe there is more advanced way to make this a responsive loop so if i would use more characters i dont need to add more for

pearl rampart
#

Return