diff --git a/src/main/java/com/example/vpr_javafx/Data.java b/src/main/java/com/example/vpr_javafx/Data.java index f8f7815..88cfd5c 100644 --- a/src/main/java/com/example/vpr_javafx/Data.java +++ b/src/main/java/com/example/vpr_javafx/Data.java @@ -1,6 +1,10 @@ package com.example.vpr_javafx; +import javafx.fxml.FXML; import javafx.scene.control.Alert; +import javafx.scene.control.Label; +import javafx.scene.control.PasswordField; +import javafx.scene.control.TextField; import java.io.File; import java.io.FileWriter; @@ -9,6 +13,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Scanner; import java.util.regex.Matcher; @@ -22,6 +27,10 @@ import java.util.regex.Pattern; */ public class Data { private String pathRead; + @FXML + private TextField tfPhone; + @FXML + private PasswordField pfPassword; public Data(String pathRead) { this.pathRead = pathRead; @@ -255,13 +264,19 @@ public class Data { * @return boolean inputValid * @author Kevin Maier */ - public boolean validateData(String password, String phoneNumber) + public boolean validateData(TextField tfPhone, PasswordField pfPassword) { boolean phoneNumberMatchFound; boolean passwordMatchFound; boolean phoneNumberValid = false; boolean passwordValid = false; + LoginDatei file = new LoginDatei("user.txt"); + HashMap users = file.readFile(); + + String phoneNumber = tfPhone.getText(); + String password = pfPassword.getText(); + Pattern phoneNumberPattern = Pattern.compile("[0-9]*"); Pattern passwordPattern = Pattern.compile("^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{8,}$"); @@ -279,7 +294,7 @@ public class Data { phoneNumberMatchFound = phoneNumberMatcher.find(); passwordMatchFound = passwordMatcher.find(); - if (!phoneNumberMatchFound || phoneNumber.length() >= 15) + if (!users.containsKey(phoneNumber) || !phoneNumberMatchFound || phoneNumber.length() >= 15) { Alert alert = new Alert(Alert.AlertType.WARNING); alert.setContentText("Login fehlgeschlagen. Die eingegebene Handynummer ist nicht valide."); @@ -291,7 +306,7 @@ public class Data { phoneNumberValid = true; } - if (!passwordMatchFound || password.length() <8) + if (!users.get(phoneNumber).equals(password) || !passwordMatchFound || password.length() <8) { Alert alert = new Alert(Alert.AlertType.WARNING); alert.setContentText("Login fehlgeschlagen. Das eingegebene Passwort ist nicht valide."); diff --git a/src/main/java/com/example/vpr_javafx/HelloController.java b/src/main/java/com/example/vpr_javafx/HelloController.java index 3b8b6aa..3b83fce 100644 --- a/src/main/java/com/example/vpr_javafx/HelloController.java +++ b/src/main/java/com/example/vpr_javafx/HelloController.java @@ -86,11 +86,13 @@ public class HelloController { private TextField tfPhone; @FXML private PasswordField pfPassword; + @FXML + private Label allergene; private Stage stage; private Scene scene; - @FXML - private Label allergene; + + @FXML private String veggieImageUrl = "pics/vegetarisch.png"; @@ -104,22 +106,8 @@ public class HelloController { @FXML protected void OnSignInButton(ActionEvent event) throws IOException { - LoginDatei file = new LoginDatei("user.txt"); - HashMap users = file.readFile(); - - String phoneNumber = tfPhone.getText(); - String password = pfPassword.getText(); - - Data data = new Data("user.txt"); - boolean inputValid = data.validateData(password, phoneNumber); - - if (users.containsKey(phoneNumber) && inputValid) - { - if (users.get(phoneNumber).equals(password)) - { - - } - } + Data data = new Data("user.txt"); + data.validateData(tfPhone, pfPassword); } diff --git a/target/classes/com/example/vpr_javafx/Data.class b/target/classes/com/example/vpr_javafx/Data.class index 006c0e6..13a593a 100644 Binary files a/target/classes/com/example/vpr_javafx/Data.class and b/target/classes/com/example/vpr_javafx/Data.class differ diff --git a/user.txt b/user.txt index 070c533..bf73a00 100644 --- a/user.txt +++ b/user.txt @@ -1,2 +1,2 @@ -Felix Düsterhaus;Sabine Gubitz;Detmolderstrasse 101,33102 Paderborn;1234567;Lisa,Peter;12345 -Kevin Pfannenstiel;Marlene Pfannenstiel;Fürstenallee 30, 33102 Paderborn;7654321;Anton;12345 +Felix Düsterhaus;Sabine Gubitz;Detmolderstrasse 101,33102 Paderborn;1234567;Lisa,Peter;12345678A +Kevin Pfannenstiel;Marlene Pfannenstiel;Fürstenallee 30, 33102 Paderborn;7654321;Anton;12345678B