|
|
@ -35,7 +35,6 @@ public class LoginGUI extends JFrame implements ActionListener { |
|
|
|
return signUpButton; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public LoginGUI() { |
|
|
|
setTitle("Login"); |
|
|
|
setSize(300, 220); |
|
|
@ -98,27 +97,23 @@ public class LoginGUI extends JFrame implements ActionListener { |
|
|
|
}else if (e.getSource() == signUpButton) { |
|
|
|
SignUpGUI signUpGUI = new SignUpGUI(); |
|
|
|
signUpGUI.setVisible(true); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void login() { |
|
|
|
String username = usernameField.getText(); |
|
|
|
String password = new String(passwordField.getPassword()); |
|
|
|
boolean stayLoggedIn = stayLoggedInCheckbox.isSelected(); // Get checkbox state |
|
|
|
|
|
|
|
if (authenticateUser(username, password)) { |
|
|
|
JOptionPane.showMessageDialog(this, "Login successful!"); |
|
|
|
// Perform actions after successful login |
|
|
|
|
|
|
|
dispose(); |
|
|
|
} else { |
|
|
|
JOptionPane.showMessageDialog(this, "Invalid username or password", "Login Error", JOptionPane.ERROR_MESSAGE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void updateStayLoggedIn(String username, boolean stayLoggedIn) { |
|
|
|
// Update stayLoggedIn in the JSON file for the user |
|
|
|
private void updateStayLoggedIn(String username, boolean stayLoggedIn) { |
|
|
|
CreateUser.updateStayLoggedIn("user.json", username, stayLoggedIn); |
|
|
|
} |
|
|
|
|
|
|
@ -128,16 +123,14 @@ public class LoginGUI extends JFrame implements ActionListener { |
|
|
|
if (userList != null) { |
|
|
|
for (CreateUser user : userList) { |
|
|
|
if (user.getUserName().equals(username)) { |
|
|
|
// Hash the user input password |
|
|
|
String hashedPassword = hashPassword(password); |
|
|
|
// Compare the hashed passwords |
|
|
|
if (user.getPassword().equals(hashedPassword)) { |
|
|
|
return true; // Success |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return false; // Fail |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private String hashPassword(String password) { |
|
|
|