-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapulation.Java
More file actions
66 lines (42 loc) · 1.55 KB
/
Copy pathMapulation.Java
File metadata and controls
66 lines (42 loc) · 1.55 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
### Main Class (MakePasswordFile)
> user passowrd making
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import javax.swing.JFileChooser;
/**
* Create a small password file
* @author Frederico Salianga
* @version 24 September 2022
*
*/
public class MakePasswordFile {
public static void main(String[] args) throws FileNotFoundException {
// Fill an array with four simple pairs
PasswordPair[] pws = new PasswordPair[4];
pws[0] = new ClearPassword("Idiot","password");
pws[1] = new ClearPassword("TooCommon","123456");
pws[2] = new ClearPassword("Insecure","Insecure");
pws[3] = new ClearPassword("fredericosalianga","pT34v!2lfG");
// Present a dialog for the user to choose the data file to be written
System.out.println("Choose where to store the file.");
final JFileChooser fc = new JFileChooser();
int returnVal = fc.showSaveDialog(fc);
// Deal with the cancel button
if (returnVal == JFileChooser.CANCEL_OPTION) {
System.out.println("Operation cancelled.");
}
// Deal with the OK button
else if (returnVal == JFileChooser.APPROVE_OPTION) {
// Open the file to be written
// (we should check whether to overwrite if it exists, but that's for another day)
PrintWriter output = new PrintWriter(fc.getSelectedFile());
// Write the data that you want
for (int i=0; i<pws.length; i++) {
output.println(pws[i]);
}
// Close the PrintWriter or the file won't exist on disk
output.close();
System.out.println("Password file written.");
}
}
}