Browse Source

refactoring: fixed indentations and removed useless comments in LoginGUI

remotes/origin/hotfix/client/improve-chat-window-appearence
Richard Schmidt 11 months ago
parent
commit
bb429f6f1d
  1. 13
      src/main/java/LoginGUI.java

13
src/main/java/LoginGUI.java

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

Loading…
Cancel
Save