-
Notifications
You must be signed in to change notification settings - Fork 1
/
User.java
68 lines (53 loc) · 1.17 KB
/
User.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
package main;
import errors.PasswordIncorrect;
import errors.WrongFormat;
public class User {
protected String id;
protected String password;
protected String fName;
protected String lName;
private static User user;
public void setUser(User user1){
user = user1;
}
User () {}
User (String id, String password, String fName, String lName){
this.id = id;
this.password = password;
this.fName = fName;
this.lName = lName;
}
public static User login(String userID, String password) throws Exception {
User user = null;
// Check for format
if (userID.contains(" ") || password.contains(" ")){
throw new WrongFormat();
}
Reader reader = new Reader();
user = reader.LoadUser(userID);
// Check for correct password
if (!user.checkPassword(password)) {
throw new PasswordIncorrect();
}
return user;
}
// Gets
public String getUserID () {
return this.id;
}
public boolean checkPassword (String password) {
if (this.password.equals(password))
return true;
else
return false;
}
public String getFirstName () {
return this.fName;
}
public String getLastName () {
return this.lName;
}
public User getUser(){
return user;
}
}