-
Notifications
You must be signed in to change notification settings - Fork 0
/
Backend
43 lines (34 loc) · 1.44 KB
/
Backend
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
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class LoginSystemBackend {
private static Map<String, String> users = new HashMap<>();
public static void main(String[] args) {
)
users.put("user1", "password1");
users.put("user2", "password2");
Scanner scanner = new Scanner(System.in);
// Welcome message
System.out.println("Welcome to the our Login System!");
// User login
System.out.print("Enter your username: ");
String username = scanner.nextLine();
System.out.print("Enter your password: ");
String password = scanner.nextLine();
// Simple authentication logic
boolean isAuthenticated = authenticateUser(username, password);
if (isAuthenticated) {
System.out.println("Login successful!");
// Proceed with further actions (like redirecting, integrating AI, etc.)
} else {
System.out.println("Invalid username or password. Please try again!");
}
}
// Method to authenticate user credentials
public static boolean authenticateUser(String username, String password) {
// Retrieve the password associated with the given username
String storedPassword = users.get(username);
// Check if the username exists and the password matches
return storedPassword != null && storedPassword.equals(password);
}
}