forked from Midway91/HactoberFest2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Authentication system
47 lines (36 loc) · 1.05 KB
/
Authentication system
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
import java.util.HashMap;
import java.util.Map;
public class AuthenticationSystem {
private Map<String, User> users;
public AuthenticationSystem() {
this.users = new HashMap<>();
}
public void registerUser(User user) {
this.users.put(user.getUsername(), user);
}
public User login(String username, String password) {
User user = this.users.get(username);
if (user != null && user.isAuthenticated(password)) {
return user;
} else {
return null;
}
}
public static class User {
private String username;
private String password;
public User(String username, String password) {
this.username = username;
this.password = password;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public boolean isAuthenticated(String password) {
return this.password.equals(password);
}
}
}