-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdmin.java
46 lines (37 loc) · 1.23 KB
/
Admin.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
import java.io.*;
import java.util.*;
import Basic.User;
public class Admin extends User{
public Admin()
{
super(-1, "admin","");
try{
Scanner fileScanner = new Scanner(new File("admin.dat"));
String data = fileScanner.nextLine();
setHashedPassword(data);
}
catch(FileNotFoundException ex)
{
System.out.println("admin.dat not found.");
System.out.println("admin set to default password.");
//set to "password" as the default password
String newHashedPassword = "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8";
setHashedPassword(newHashedPassword);
}
}
//overide the super class method
public void setHashedPassword(String newHashedPassword)
{
try
{
PrintWriter fileOut = new PrintWriter("admin.dat");
fileOut.print(newHashedPassword);
fileOut.close();
super.setHashedPassword(newHashedPassword);
}
catch(IOException e)
{
System.out.println("Failed to open admin.dat, password not updated");
}
}
}