-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordGenerator.java
More file actions
28 lines (22 loc) · 884 Bytes
/
PasswordGenerator.java
File metadata and controls
28 lines (22 loc) · 884 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
28
import java.util.Random;
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 = "!@#$%^&*()-_+=<>?";
private static final String ALL_CHARS = UPPER + LOWER + DIGITS + SPECIAL;
private static final Random random = new Random();
public static String generatePassword(int length){
StringBuilder password = new StringBuilder(length);
for (int i = 0; i < length; i++){
int index = random.nextInt(ALL_CHARS.length());
password.append(ALL_CHARS.charAt(index));
}
return password.toString();
}
public static void main(String[] arga){
int length = 12;
String password = generatePassword(length);
System.out.println("Generated Password:" + password);
}
}