-
Notifications
You must be signed in to change notification settings - Fork 1
/
UserStorage.java
80 lines (70 loc) · 1.66 KB
/
UserStorage.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
import java.util.Hashtable;
/**
* UserStorage is the 'database' of all users of the software
*
* @author Kimberly Lalmansingh
*
*/
public class UserStorage {
Hashtable<String, User> users;
private String admin = "Admin";
private String adminpass = "pass0000";
private String user1 = "kim";
private String pass1 = "pass";
private String user2 = "Guest";
private String pass2 = null;
/**
* Constructor
*/
public UserStorage(){
User adminUser = new User(admin, adminpass);
User regularUser1 = new User(user1, pass1);
User regularUser2 = new User(user2, pass2);
users = new Hashtable<String, User>();
users.put(admin, adminUser);
users.put(user1, regularUser1);
users.put(user2, regularUser2);
}
/**
*
* @return hashtable containing users
*/
public Hashtable<String, User> getUsers(){
return users;
}
/**
* @param username - username to add
* @param password - password to add
*/
public void addUser(String username, String password){
User newUser = new User(username, password);
users.put(username, newUser);
}
/**
*
* @param username - user to remove
*/
public void deleteUser(String username){
if(users.containsKey(username)){
users.remove(username);
}
}
/**
*
* @param username - user to check
* @return true if it is admin, false otherwise
*/
public boolean isAdmin(String username){
if(username.equals("Admin")) return true;
else return false;
}
/**
*
* @param username - user to check
* @return true if user exists, false otherwise
*/
public boolean userExists(String username){
if(users.containsKey(username)) return true;
else return false;
}
} //end class UserStorage