-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSysAdmin.java
91 lines (78 loc) · 2.18 KB
/
SysAdmin.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
/*
* System Admin Login Class
* Reads a file to determine if the last login was successful
* If last login was successful the program will default to the login screen
* if previous login and admin login failed, SysAdmin will load.
*/
package natasha;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import static natasha.Natasha.print;
/**
*
* @author Gary
*/
public class SysAdmin {
Scanner keyboard = new Scanner(System.in);
private String filePath;
private Scanner input = null;
private String lastLogin;
private String sysLogin;
public SysAdmin(String filePath) {
this.filePath = filePath;
File inputFile = new File(filePath);
this.lastLogin = lastLogin;
this.sysLogin = "sysAd";
try {
this.input = new Scanner(inputFile);
} catch (FileNotFoundException ex) {
Logger.getLogger(PasswordReader.class.getName()).log(Level.SEVERE, null, ex);
}
}
public boolean checkLast() {
boolean goodToGo = true;
while (this.input.hasNext()) {
this.lastLogin = this.input.nextLine();
if (this.lastLogin.equals("FAIL")) {
goodToGo = false;
}
}
return goodToGo;
}
public void Login() {
print("System Admin: ");
String login = keyboard.nextLine();
if (!this.sysLogin.equals("sysAd")) {
System.exit(0);
}
}
public void writeLast(boolean accepted) {
FileWriter lastWriter = null;
PrintWriter outFile = null;
try {
lastWriter = new FileWriter("sysadmin.txt", false);
outFile = new PrintWriter(lastWriter);
} catch (IOException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
}
outFile.println("# System Admin login class file");
outFile.println("# PASS / FAIL");
if (accepted) {
outFile.println("PASS");
} else {
outFile.println("FAIL");
}
try {
lastWriter.close();
} catch (IOException ex) {
Logger.getLogger(SysAdmin.class.getName()).log(Level.SEVERE, null, ex);
}
}
}