Merge remote-tracking branch 'origin/main'

# Conflicts:
#	target/classes/com/example/vpr_javafx/HelloController.class
This commit is contained in:
Felix Düsterhaus 2023-01-30 17:47:34 +01:00
commit 7b0ba5aee6
4 changed files with 26 additions and 23 deletions

View File

@ -1,6 +1,10 @@
package com.example.vpr_javafx; package com.example.vpr_javafx;
import javafx.fxml.FXML;
import javafx.scene.control.Alert; 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.File;
import java.io.FileWriter; import java.io.FileWriter;
@ -9,6 +13,7 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -22,6 +27,10 @@ import java.util.regex.Pattern;
*/ */
public class Data { public class Data {
private String pathRead; private String pathRead;
@FXML
private TextField tfPhone;
@FXML
private PasswordField pfPassword;
public Data(String pathRead) { public Data(String pathRead) {
this.pathRead = pathRead; this.pathRead = pathRead;
@ -255,13 +264,19 @@ public class Data {
* @return boolean inputValid * @return boolean inputValid
* @author Kevin Maier * @author Kevin Maier
*/ */
public boolean validateData(String password, String phoneNumber) public boolean validateData(TextField tfPhone, PasswordField pfPassword)
{ {
boolean phoneNumberMatchFound; boolean phoneNumberMatchFound;
boolean passwordMatchFound; boolean passwordMatchFound;
boolean phoneNumberValid = false; boolean phoneNumberValid = false;
boolean passwordValid = false; boolean passwordValid = false;
LoginDatei file = new LoginDatei("user.txt");
HashMap<String, String> users = file.readFile();
String phoneNumber = tfPhone.getText();
String password = pfPassword.getText();
Pattern phoneNumberPattern = Pattern.compile("[0-9]*"); Pattern phoneNumberPattern = Pattern.compile("[0-9]*");
Pattern passwordPattern = Pattern.compile("^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{8,}$"); Pattern passwordPattern = Pattern.compile("^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{8,}$");
@ -279,7 +294,7 @@ public class Data {
phoneNumberMatchFound = phoneNumberMatcher.find(); phoneNumberMatchFound = phoneNumberMatcher.find();
passwordMatchFound = passwordMatcher.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 alert = new Alert(Alert.AlertType.WARNING);
alert.setContentText("Login fehlgeschlagen. Die eingegebene Handynummer ist nicht valide."); alert.setContentText("Login fehlgeschlagen. Die eingegebene Handynummer ist nicht valide.");
@ -291,7 +306,7 @@ public class Data {
phoneNumberValid = true; 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 alert = new Alert(Alert.AlertType.WARNING);
alert.setContentText("Login fehlgeschlagen. Das eingegebene Passwort ist nicht valide."); alert.setContentText("Login fehlgeschlagen. Das eingegebene Passwort ist nicht valide.");

View File

@ -86,11 +86,13 @@ public class HelloController {
private TextField tfPhone; private TextField tfPhone;
@FXML @FXML
private PasswordField pfPassword; private PasswordField pfPassword;
@FXML
private Label allergene;
private Stage stage; private Stage stage;
private Scene scene; private Scene scene;
@FXML
private Label allergene;
@FXML @FXML
private String veggieImageUrl = "pics/vegetarisch.png"; private String veggieImageUrl = "pics/vegetarisch.png";
@ -104,22 +106,8 @@ public class HelloController {
@FXML @FXML
protected void OnSignInButton(ActionEvent event) throws IOException protected void OnSignInButton(ActionEvent event) throws IOException
{ {
LoginDatei file = new LoginDatei("user.txt"); Data data = new Data("user.txt");
HashMap<String, String> users = file.readFile(); data.validateData(tfPhone, pfPassword);
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))
{
}
}
} }

View File

@ -1,2 +1,2 @@
Felix Düsterhaus;Sabine Gubitz;Detmolderstrasse 101,33102 Paderborn;1234567;Lisa,Peter;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;12345 Kevin Pfannenstiel;Marlene Pfannenstiel;Fürstenallee 30, 33102 Paderborn;7654321;Anton;12345678B