Skip to content

Commit 2a61607

Browse files
Random Password Generator
1 parent abd03c5 commit 2a61607

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

Random Password Generator.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import java.util.*;
1+
import java.security.SecureRandom;
22

33
public class PasswordGen {
44
public static void main(String[] args) {
55
String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@#$%";
6-
Random r = new Random();
7-
String pass = "";
6+
SecureRandom r = new SecureRandom();
7+
StringBuilder pass = new StringBuilder();
88

9-
for (int i = 0; i < 10; i++)
10-
pass += chars.charAt(r.nextInt(chars.length()));
9+
for (int i = 0; i < 10; i++) {
10+
pass.append(chars.charAt(r.nextInt(chars.length())));
11+
}
1112

1213
System.out.println("Generated Password: " + pass);
1314
}

0 commit comments

Comments
 (0)