forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOTP-generator.java
37 lines (27 loc) · 837 Bytes
/
OTP-generator.java
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
32
33
34
35
36
37
// Java OTP generator using random() method
import java.util.*;
class Main {
public static void main(String[] args)
{
int length = 10;
System.out.println(Password(length));
}
static char[] Password(int len)
{
System.out.println("Generating password using random() : ");
System.out.print("Your new password is : ");
String Capital_letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String Small_letters = "abcdefghijklmnopqrstuvwxyz";
String numbers = "0123456789";
String symbols = "!@#$%^&*_=+-/.?<>)";
String values = Capital_letters + Small_letters + numbers + symbols;
Random random_method = new Random();
char[] password = new char[len];
for (int i = 0; i < len; i++)
{
password[i] =
values.charAt(random_method.nextInt(values.length()));
}
return password;
}
}