forked from vishnu2k60/HacktoberFest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordGenerator.java
More file actions
23 lines (23 loc) · 876 Bytes
/
PasswordGenerator.java
File metadata and controls
23 lines (23 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//Password Generator [Note:- Provide only length for password]
import java.util.*;
public class RandomPasswordGenerator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Length of Password");
int n = sc.nextInt();
System.out.println(passwordGenerator(n));
}
static String passwordGenerator(int len) {
String Capital_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String Small_chars = "abcdefghijklmnopqrstuvwxyz";
String numbers = "0123456789";
String symbols = "!@#$%^&*_=+-/.?<>)";
String values = Capital_chars+Small_chars+numbers+symbols;
Random rndm_method = new Random();
char[] password = new char[len];
for(int i=0;i<len;i++) {
password[i] = values.charAt(rndm_method.nextInt(values.length()));
}
return String.valueOf(password);
}
}