What's wrong with my regex or statement in cycle? I need 8-chars combination with one digit, one letter in upper case and one in lower case minimum. But I get a non-stop cycle.
public static ByteArrayOutputStream getPassword() throws IOException{
char[] chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray();
Random random = new Random();
String out = "";
ByteArrayOutputStream stream = new ByteArrayOutputStream();;
while (!out.matches("[0-9]+$") | !out.matches("[a-z]+$") | !out.matches("[A-Z]+$")) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 8; i++) {
char c = chars[random.nextInt(chars.length)];
sb.append(c);
}
out = sb.toString();
}
stream.write(out.getBytes());
return stream;
}