-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordGenerator.java
More file actions
27 lines (21 loc) · 842 Bytes
/
Copy pathPasswordGenerator.java
File metadata and controls
27 lines (21 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util
public class PasswordGenerator{
private static final String UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static final String LOWER = "abcdefghijklmnopqrstuvwxyz";
private static final String DIGITS = "0123456789";
private static final String SPECIAL = "!@#$%^&*()-_+=<>?";
public static final String ALL_CHARS = UPPER + LOWER + DIGITS + SPECIAL;
private static final Random random = new();
private static String generatePassword(int length) {
StringBuilder password = new StringBuilder(length);
for (int i = 0; < length; i++) {
int index = random.nextInt(All_CHARS, length());
password.append(All_CHARS.charAt(index));
}
}
public static void main(String[] args) {
int length = 12;
String password = generatePassword(length);
System.out.println("Generate Password: " + password);
}
}