-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserStore.java
More file actions
23 lines (19 loc) · 776 Bytes
/
UserStore.java
File metadata and controls
23 lines (19 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.HashMap;
import java.util.Map;
public class UserStore {
private Map<String, String> users = new HashMap<>(); // Stores usernames and passwords
public boolean authenticateUser(String username, String password) {
return users.containsKey(username) && users.get(username).equals(password);
}
public boolean registerUser(String username, String password) {
if (users.containsKey(username)) {
return false; // User already exists
}
users.put(username, password);
return true;
}
public User getUser(String username) {
String password = users.get(username);
return new User(username, password); // assuming User class has this constructor
}
}