|
|
@ -43,11 +43,28 @@ public class LoginGUI extends JFrame implements ActionListener { |
|
|
|
String username = usernameField.getText(); |
|
|
|
String password = new String(passwordField.getPassword()); |
|
|
|
|
|
|
|
//Add login functionality |
|
|
|
JOptionPane.showMessageDialog(this, "Login"); |
|
|
|
if (authenticateUser(username, password)) { |
|
|
|
JOptionPane.showMessageDialog(this, "Login successful!"); |
|
|
|
// Perform actions after successful login |
|
|
|
} else { |
|
|
|
JOptionPane.showMessageDialog(this, "Invalid username or password", "Login Error", JOptionPane.ERROR_MESSAGE); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Function to authenticate the user by comparing the entered username and password with the saved user data |
|
|
|
private boolean authenticateUser(String username, String password) { |
|
|
|
List<CreateUser> userList = CreateUser.readUserListFromJsonFile("user.json"); |
|
|
|
if (userList != null) { |
|
|
|
for (CreateUser user : userList) { |
|
|
|
if (user.getUserName().equals(username) && user.getPassword().equals(password)) { |
|
|
|
return true; //Success |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return false; // Fail |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|