Skip to content

Commit 50aba68

Browse files
authored
Create Authentication System
1 parent 104e5f0 commit 50aba68

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

Authentication System

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import java.util.HashMap;
2+
import java.util.Map;
3+
4+
public class AuthenticationSystem {
5+
6+
private Map<String, User> users;
7+
8+
public AuthenticationSystem() {
9+
this.users = new HashMap<>();
10+
}
11+
12+
public void registerUser(User user) {
13+
this.users.put(user.getUsername(), user);
14+
}
15+
16+
public User login(String username, String password) {
17+
User user = this.users.get(username);
18+
if (user != null && user.isAuthenticated(password)) {
19+
return user;
20+
} else {
21+
return null;
22+
}
23+
}
24+
25+
public static class User {
26+
27+
private String username;
28+
private String password;
29+
30+
public User(String username, String password) {
31+
this.username = username;
32+
this.password = password;
33+
}
34+
35+
public String getUsername() {
36+
return username;
37+
}
38+
39+
public String getPassword() {
40+
return password;
41+
}
42+
43+
public boolean isAuthenticated(String password) {
44+
return this.password.equals(password);
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)