public static String getCorrectPinFromUser() {
        String password = "";
        try {
            do {
                Console c = System.console();
                char[] passwordarray = c.readPassword("Password: ");
                password = String.valueOf(passwordarray);
                if (!password.matches("\\d{4,8}")) {
                    System.err.println("PIN must only have characters 0-9 from range 4 to 8.");
                } else {
                    return password;
                }
            } while (true);

        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        return password;
    }