-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate_User.java
More file actions
141 lines (92 loc) · 3.91 KB
/
Create_User.java
File metadata and controls
141 lines (92 loc) · 3.91 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package Default;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Scanner;
import java.io.File;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Create_User {
public static void main(String args[]){
try {
File File = new File("userlog.txt");
FileWriter fw = new FileWriter(File,true);
BufferedWriter br = new BufferedWriter(fw);
br.write("");
System.out.print("Enter New Username: ");
Scanner scan = new Scanner(System.in);
String user = scan.nextLine();
FileWriter fWriter = null;
BufferedWriter writer = null;
Scanner scanner = new Scanner(new File("userlog.txt"));
String lines = "";
boolean checkExists = false;
while(scanner.hasNextLine()) {
lines = scanner.nextLine();
String[] userCompare = lines.split(":");
if (userCompare[0].contentEquals(user)) {
checkExists = true;
}
}
//writes username to new file 'userlog.txt' with format 'user:password'
// File File = new File("userlog.txt");
// FileWriter fw = new FileWriter(File,true);
// BufferedWriter br = new BufferedWriter(fw);
if (!checkExists) {
br.write(user);
br.write(":");
// writes corresponding password converted to md5
System.out.print("Enter Password: ");
String pass = scan.nextLine();
br.write(md5(pass));
Scanner scanner2 = new Scanner(new File("dictionary.txt"));
Scanner scanner3 = new Scanner(new File("dictionary.txt"));
String passMatch ="";
String baseword = "";
String strength = "";
while(scanner2.hasNextLine()) {
passMatch = scanner2.nextLine();
if (passMatch.contentEquals(pass)) {
strength = "weak";
}
}
scanner2.close();
if(strength.contentEquals("")) {
while(scanner3.hasNextLine()) {
baseword = scanner3.nextLine();
//System.out.println(baseword);
//System.out.println(pass);
if (pass.contains(baseword)) {
strength = "moderate";
} else if (strength.contentEquals("")){
strength = "strong";
}
}
}
br.newLine();
br.close();
fw.close();
System.out.println("Password strength: "+ strength);
} else {
System.out.println("user already exists!");
}
} catch (Exception e) {
System.out.println("Error!");
}
}
public static String md5(String input) {
String md5 = null;
if(null == input) return null;
try {
//Create MessageDigest object for MD5
MessageDigest digest = MessageDigest.getInstance("MD5");
//Update input string in message digest
digest.update(input.getBytes(), 0, input.length());
//Converts message digest value in base 16 (hex)
md5 = new BigInteger(1, digest.digest()).toString(16);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return md5;
}
}