Browse Source

Added logic for checking if username / password exist

remotes/origin/server
Richard Schmidt 11 months ago
parent
commit
96111842f4
  1. 21
      src/main/java/LoginGUI.java

21
src/main/java/LoginGUI.java

@ -43,13 +43,30 @@ public class LoginGUI extends JFrame implements ActionListener {
String username = usernameField.getText(); String username = usernameField.getText();
String password = new String(passwordField.getPassword()); 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
}
public static void main(String[] args) { public static void main(String[] args) {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {

Loading…
Cancel
Save