Skip to content
Snippets Groups Projects
Commit 9af9e210 authored by Eilert Tunheim's avatar Eilert Tunheim
Browse files

Gives user feedback if username or password is wrong

parent eedbc3da
Branches
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import com.google.cloud.bigquery.TableResult;
import static com.application.DB.Constants.*;
import static com.application.DB.Settings.*;
import static com.application.GUI.PopUpWindows.LoginPopup.getPasswordTextField;
public class Account_handler {
......@@ -41,6 +42,7 @@ public class Account_handler {
}
} else {
NotificationPopUp.displayNotificationWindow("Wrong username or password!");
getPasswordTextField().clear();
}
}
......
......@@ -12,6 +12,8 @@ import javafx.scene.layout.Region;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import static com.application.DB.Constants.isIsAdmin;
public class LogoBar {
private static Button login = new Button("Login");
......@@ -45,22 +47,19 @@ public class LogoBar {
HBox.setHgrow(region2, Priority.ALWAYS);
// Login button
getLogin().setOnAction(event -> {
if(getLogin().getText().equals("Login")){
LoginPopup.login();
getLogin().setOnAction(event -> {
if(getLogin().getText().equals("Login")){
LoginPopup.login();
} else {
if(isIsAdmin()){
LoginPopup.adminPopup();
} else {
System.out.println("Logget inn");
LoginPopup.userPopup();
}
}
});
});
return new HBox(imageViewM, region1, imageViewTitle, region2, login);
return new HBox(imageViewM, region1, imageViewTitle, region2, getLogin());
}
public static Button getLogin() {
......
......@@ -21,6 +21,8 @@ import static com.application.DB.Account_handler.getAccount;
public class LoginPopup {
public static PasswordField PASSWORD_TEXT_FIELD = new PasswordField();
public static void login(){
Stage window = new Stage();
......@@ -31,7 +33,6 @@ public class LoginPopup {
Label passwordLabel = new Label("Password:");
TextField userNameTextField = new TextField();
PasswordField passwordTextField = new PasswordField();
Button closeButton = new Button("Close");
Button loginButton = new Button("Login");
......@@ -43,7 +44,7 @@ public class LoginPopup {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
assert messageDigest != null;
messageDigest.update(passwordTextField.getText().getBytes(StandardCharsets.UTF_8));
messageDigest.update(getPasswordTextField().getText().getBytes(StandardCharsets.UTF_8));
byte[] hashedPassword = messageDigest.digest();
......@@ -72,11 +73,49 @@ public class LoginPopup {
VBox layout = new VBox(10);
layout.setAlignment(Pos.CENTER);
layout.getChildren().addAll(userNameLabel, userNameTextField, passwordLabel, passwordTextField, loginButton, closeButton);
layout.getChildren().addAll(userNameLabel, userNameTextField, passwordLabel, getPasswordTextField(), loginButton, closeButton);
Scene scene = new Scene(layout, 500, 300);
scene.getStylesheets().add(InputPopup.class.getResource("/com.application/CSS/styleSheet.css").toExternalForm());
window.setScene(scene);
window.showAndWait();
}
public static void adminPopup(){
Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("Login window");
VBox layout = new VBox(10);
layout.setAlignment(Pos.CENTER);
layout.getChildren().addAll();
Scene scene = new Scene(layout, 500, 300);
scene.getStylesheets().add(InputPopup.class.getResource("/com.application/CSS/styleSheet.css").toExternalForm());
window.setScene(scene);
window.showAndWait();
}
public static void userPopup(){
Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("Login window");
VBox layout = new VBox(10);
layout.setAlignment(Pos.CENTER);
layout.getChildren().addAll();
Scene scene = new Scene(layout, 500, 300);
scene.getStylesheets().add(InputPopup.class.getResource("/com.application/CSS/styleSheet.css").toExternalForm());
window.setScene(scene);
window.showAndWait();
}
public static PasswordField getPasswordTextField() {
return PASSWORD_TEXT_FIELD;
}
}
No preview for this file type
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment