Fixed login and register errors.

This commit is contained in:
Asal Lotfi
2025-08-30 17:14:04 +03:30
parent fe70aa6bd7
commit dff7b82e34
2 changed files with 21 additions and 1 deletions
@@ -113,7 +113,25 @@ public class LoginController {
private void handleLogin() {
String u = usernameField.getText().trim();
String p = passwordField.getText();
if (u.isEmpty() || p.isEmpty()) { showError("Please fill in all required fields."); return; }
// 1. Check for empty fields
if (u.isEmpty() || p.isEmpty()) {
showError("Please fill in all required fields.");
return;
}
// 2. Check if username exists
userDatabase userDb = new userDatabase();
if (!userDb.existsByUsername(u)) {
showError("This username doesnt exist.");
return;
}
// 3. Check if password is correct
User user = userDb.findByUsername(u);
if (!PasswordHashing.verify(p, user.getPassword())) {
showError("Incorrect password.");
return;
}
setUiBusy(true);
@@ -182,6 +200,7 @@ public class LoginController {
PauseTransition pause = new PauseTransition(Duration.millis(50));
pause.setOnFinished(event -> {
errorLabel.setText(message);
errorLabel.setStyle("-fx-text-fill: red;"); // 🔴 force red
errorLabel.setVisible(true);
});
pause.play();
@@ -156,6 +156,7 @@ public class RegisterController {
PauseTransition pause = new PauseTransition(Duration.millis(50));
pause.setOnFinished(event -> {
errorLabel.setText(message);
errorLabel.setStyle("-fx-text-fill: red;"); // 🔴 force red
errorLabel.setVisible(true);
});
pause.play();