Не проходят 2 и 6 условия
package com.javarush.task.task32.task3204;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Random;
/*
Генератор паролей
*/
public class Solution {
public static void main(String[] args) throws IOException {
ByteArrayOutputStream password = getPassword();
System.out.println(password.toString());
}
public static ByteArrayOutputStream getPassword() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] bytes = new byte[8];
for (int i = 0; i < bytes.length; i++) {
int number;
while (true) {
number = getRandomByteInRange();
if ((number >= 65 && number <= 90)
|| (number >= 97 && number <= 122)
|| (number >= 48 && number <= 57)) {
}break;
}
bytes[i] = (byte) number;
}
String password = new String(bytes, StandardCharsets.UTF_8);
if(!checkPass(password)) {
return getPassword();
} else {
try {
baos.write(password.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
return baos;
}
}
private static int getRandomByteInRange() {
// generate symbol and add it to byte array
// 65 - 90 LETTERS
// 97 - 122 letters
// 48 - 57 numbers
int number = new Random().nextInt();
return number;
}
public static boolean checkPass(String password) {
// write regexp
if (password.matches("(.*[0-9]+.*)") && password.matches("(.*[a-z]+.*)")
&& password.matches("(.*[A-Z]+.*)")) {
return true;
} else {
return false;
}
}
}