-
Notifications
You must be signed in to change notification settings - Fork 0
/
PasswordGenerator.java
109 lines (91 loc) · 1.96 KB
/
PasswordGenerator.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import java.io.*;
import java.util.*;
import java.util.Random;
class PasswordGenerator
{
public static void main (String [] args)
{
Length l = new Length();
Generate g = new Generate();
int random;
l.get();
for(int k = 0; k < l.length; k++)
{
random = new Random().nextInt(4);
if(random == 0)
{
g.digit(l);
}
if(random == 1)
{
g.lowercase(l);
}
if(random == 2)
{
g.uppercase(l);
}
if(random == 3)
{
g.character(l);
}
}
System.out.println("Your Randomly Generated Password Is: ");
for(int j = 0; j < l.length; j++)
{
System.out.print(l.password[j]);
}
}
}
class Length
{
int length = 0;
String [] password = new String [1000];
void get()
{
System.out.println("Enter Desired Password Length: ");
Scanner in = new Scanner(System.in);
while(length < 6)
{
try
{
length = in.nextInt();
} catch(Exception e)
{
System.out.println("Input Error");
e.printStackTrace();
}
if(length < 6)
{
System.out.println("Your Password Must Be Greater Than 6 To Be Secure, Please Re-Enter!");
}
}
}
}
class Generate
{
int i = 0;
String [] digits = {"1","2","3","4","5","6","7","8","9"};
String[] lowercase = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
String [] uppercase = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
String [] characters = {"~","!","@","#","$","%","^","&","*","(",")","_","-","+","=","{","}","[","]","|",":",";","<",">",".","?"};
void digit(Length l)
{
l.password[i] = digits[new Random().nextInt(8)];
i++;
}
void lowercase(Length l)
{
l.password[i] = lowercase[new Random().nextInt(25)];
i++;
}
void uppercase(Length l)
{
l.password[i] = uppercase[new Random().nextInt(25)];
i++;
}
void character(Length l)
{
l.password[i] = characters[new Random().nextInt(25)];
i++;
}
}