-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathpassword.java
More file actions
31 lines (25 loc) · 891 Bytes
/
password.java
File metadata and controls
31 lines (25 loc) · 891 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
29
30
31
import java.util.Random;
public class PasswordGenerator
{
public static void main(String[] args)
{
int length = 10; // password length(can be changed)
System.out.println(generatePswd(length));
}
static String generatePswd(int len)
{
System.out.println("Your Password:");
String charsCaps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String chars = "abcdefghijklmnopqrstuvwxyz";
String nums = "0123456789";
String symbols = "!@#$%^&*_=+-/€.?<>)";
String passSymbols = charsCaps + chars + nums + symbols;
Random rnd = new Random();
String password="";
for (int i = 0; i < len; i++)
{
password += String.valueOf(passSymbols.charAt(rnd.nextInt(passSymbols.length())));
}
return password;
}
}