-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordGenerator.java
More file actions
60 lines (53 loc) · 1.64 KB
/
Copy pathPasswordGenerator.java
File metadata and controls
60 lines (53 loc) · 1.64 KB
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
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
public class PasswordGenerator {
private static String filename = "/home/brian/eclipse/eclipse-workspace/PasswordGen/src/WordList.txt";
private static List<String> records = new ArrayList<String>();
//private static String filename = "WordList.txt";
public static void main(String[] args) {
try {
BufferedReader reader = new BufferedReader(new FileReader(filename));
String line;
while ((line = reader.readLine()) != null) {
records.add(line);
}
reader.close();
}
catch (Exception e) {
System.err.format("Exception occurred trying to read '%s'.", filename);
e.printStackTrace();
return;
}
Scanner keyboard = new Scanner(System.in);
String result = "";
System.out.println("Enter the number of words");
int numWords = keyboard.nextInt();
while(numWords < 1) {
System.out.println("Must be greater than 0");
numWords = keyboard.nextInt();
}
System.out.println("Max number");
int maxNum = keyboard.nextInt();
while(maxNum < 2) {
System.out.println("Must be greater than 1");
maxNum = keyboard.nextInt();
}
keyboard.close();
for(int i = 0; i < numWords; i++) {
result += makePart(maxNum);
}
System.out.println(result);
}
private static String makePart(int maxNum) {
Random rand = new Random();
String s = records.get(rand.nextInt(records.size()));
int n = rand.nextInt(maxNum);
Integer.toString(n);
String numString = String.format("%0" + Integer.toString(maxNum).length() + "d", n);
return s + numString;
}
}