Сгенеренные пароли
1498pvM2
8R9zCFJi
aSn1o7xh
u1o4fLHo
EFkGNV8S
ZC02QL5u
7cK3746f
T1HhqZ4L
glUR3LAP
370f9bY6
2zSlEJMn
hKl7Mg91
cWOT1Qgt
M8lzEbP7
package com.javarush.task.task32.task3204;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/*
Генератор паролей
*/
public class Solution {
public static void main(String[] args) throws IOException {
ByteArrayOutputStream password = getPassword();
System.out.println(password.toString());
}
public static ByteArrayOutputStream getPassword() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(8);
int[] mas = new int[8];
byte[] b = new byte[8];
boolean isNumber = false;
boolean isCharLow = false;
boolean isCharUp = false;
for (int i = 0; i < mas.length; i++) {
int ran = (int) (Math.random() * 3);
if (ran == 0) {
mas[i] = 48 + (int) ((Math.random() * (58 - 48)));
}
else if (ran == 1) {
mas[i] = 97 + (int) ((Math.random() * (123 - 96)));
}
else if (ran == 2) {
mas[i] = 65 + (int) ((Math.random() * (91 - 65)));
}
}
for (int i = 0; i < b.length; i++) {
b[i] = (byte) mas[i];
}
baos.write(b);
String pass = baos.toString();
for (int i = 0; i < 8; i++) {
String f = pass.substring(i, i + 1);
char symbol = f.charAt(0);
if (Character.isDigit(symbol)) {
isNumber = true;
}
else if (Character.isUpperCase(symbol)) {
isCharUp = true;
}
else if (Character.isLowerCase(symbol)) {
isCharLow = true;
}
}
if (isNumber && isCharLow && isCharUp) {
return baos;
}
else {
getPassword();
}
return null;
}
}