Login Validate geändert und für javaFx angepasst

This commit is contained in:
Kevin Pfannenstiel 2023-01-30 12:23:17 +01:00
parent 2fe71cbe7e
commit 2f3f6a11f3
7 changed files with 98 additions and 130 deletions

View File

@ -1,5 +1,7 @@
package com.example.vpr_javafx;
import javafx.scene.control.Alert;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
@ -252,9 +254,8 @@ public class Data {
* @return boolean inputValid
* @author Kevin Maier
*/
private boolean validateData(String password, String phoneNumber)
public boolean validateData(String password, String phoneNumber)
{
boolean inputValid = false;
boolean phoneNumberMatchFound;
boolean passwordMatchFound;
boolean phoneNumberValid = false;
@ -263,16 +264,12 @@ public class Data {
Pattern phoneNumberPattern = Pattern.compile("[0-9]*");
Pattern passwordPattern = Pattern.compile("^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{8,}$");
Scanner reader = new Scanner(System.in);
while(password.isEmpty() || phoneNumber.isEmpty())
if (password.isEmpty() || phoneNumber.isEmpty())
{
System.out.println("Login fehlgeschlagen. Eingabe ist leer, versuchen Sie es erneut.");
System.out.println("");
System.out.print("Telefonnummer: ");
phoneNumber = reader.nextLine();
System.out.print("Passwort: ");
password = reader.nextLine();
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setContentText("Login fehlgeschlagen. Die eingegebene Handynummer ist nicht valide.");
alert.show();
return false;
}
Matcher phoneNumberMatcher = phoneNumberPattern.matcher(phoneNumber);
@ -281,36 +278,35 @@ public class Data {
phoneNumberMatchFound = phoneNumberMatcher.find();
passwordMatchFound = passwordMatcher.find();
while (!inputValid) {
if (!phoneNumberMatchFound || phoneNumber.length() != 15) {
System.out.println("Login fehlgeschlagen. Die eingegebene Handynummer ist nicht valide.");
System.out.println("");
System.out.print("Telefonnummer: ");
phoneNumber = reader.nextLine();
System.out.print("Passwort: ");
password = reader.nextLine();
} else {
phoneNumberValid = true;
}
if (!passwordMatchFound || password.length() < 6 || password.length() > 20) {
System.out.println("Login fehlgeschlagen. Das eingegebene Passwort ist nicht valide.");
System.out.println("");
System.out.print("Telefonnummer: ");
phoneNumber = reader.nextLine();
System.out.print("Passwort: ");
password = reader.nextLine();
} else {
passwordValid = true;
}
if (phoneNumberValid && passwordValid) {
inputValid = true;
}
if (!phoneNumberMatchFound || phoneNumber.length() >= 15)
{
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setContentText("Login fehlgeschlagen. Die eingegebene Handynummer ist nicht valide.");
alert.show();
return false;
}
return inputValid;
else
{
phoneNumberValid = true;
}
if (!passwordMatchFound || password.length() <8)
{
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setContentText("Login fehlgeschlagen. Das eingegebene Passwort ist nicht valide.");
alert.show();
return false;
}
else
{
passwordValid = true;
}
return phoneNumberValid && passwordValid;
}
/**
* The method changes the orders.txt file by removing canceled orders
*

View File

@ -70,133 +70,109 @@ public class HelloController {
{
LoginDatei file = new LoginDatei("user.txt");
HashMap<String, String> users = file.readFile();
Alert alert = new Alert(Alert.AlertType.INFORMATION);
if (users.containsKey(tfPhone.getText()))
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.containsValue(pfPassword.getText()))
if (users.get(phoneNumber).equals(password))
{
Parent root = FXMLLoader.load(getClass().getResource("MenuSelect-view.fxml"));
stage = (Stage)((Node)event.getSource()).getScene().getWindow();
scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
else
{
alert.setContentText("Falsche Werte");
alert.show();
FillLabels();
}
}
else
{
alert.setContentText("Falsche Werte");
alert.show();
}
}
}
@FXML
protected void FillLabels() {
try {
List<String> menu = Files.readAllLines(Paths.get("menue.txt"));
List<String> menu = Files.readAllLines(Paths.get("menue.txt"));
for (int i = 0; i < menu.size(); i++)
{
String[] parts = menu.get(i).split(";");
for (int i = 0; i < menu.size(); i++)
{
String[] parts = menu.get(i).split(";");
String dish = parts[1];
String sideDish = parts[2];
String dish = parts[1];
String sideDish = parts[2];
String dayMenu = dish+"\n"+sideDish;
String dayMenu = dish+"\n"+sideDish;
if (i == 0)
{
switch (i) {
case 0:
lMonH1.setText(dayMenu);
}
else if (i == 1)
{
break;
case 1:
lMonD1.setText(dayMenu);
}
else if (i == 2)
{
break;
case 2:
lMonH2.setText(dayMenu);
}
else if (i == 3)
{
break;
case 3:
lMonD2.setText(dayMenu);
}
else if (i == 4)
{
break;
case 4:
lTueH1.setText(dayMenu);
}
else if (i == 5)
{
break;
case 5:
lTueD1.setText(dayMenu);
}
else if (i == 6)
{
break;
case 6:
lTueH2.setText(dayMenu);
}
else if (i == 7)
{
break;
case 7:
lTueD2.setText(dayMenu);
}
else if (i == 8)
{
break;
case 8:
lWednH1.setText(dayMenu);
}
else if (i == 9)
{
break;
case 9:
lWednD1.setText(dayMenu);
}
else if (i == 10)
{
break;
case 10:
lWednH2.setText(dayMenu);
}
else if (i == 11)
{
break;
case 11:
lWednD2.setText(dayMenu);
}
else if (i == 12)
{
break;
case 12:
lThurH1.setText(dayMenu);
}
else if (i == 13)
{
break;
case 13:
lThurD1.setText(dayMenu);
}
else if (i == 14)
{
break;
case 14:
lThurH2.setText(dayMenu);
}
else if (i == 15)
{
break;
case 15:
lThurD2.setText(dayMenu);
}
else if (i == 16)
{
break;
case 16:
lFriH1.setText(dayMenu);
}
else if (i == 17)
{
break;
case 17:
lFriD1.setText(dayMenu);
}
else if (i == 18)
{
break;
case 18:
lFriH2.setText(dayMenu);
}
else if (i == 19)
{
break;
case 19:
lFriD2.setText(dayMenu);
}
break;
}
}
catch (IOException e) {
e.printStackTrace();
}
}
catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -80,8 +80,4 @@ public class User {
* @return a String with nameParent1, nameparent2, billAdress, phonenumber, nameChildren, password
* @author Madeleine Vigier
*/
@Override
public String toString() {
return nameParent1 + ";" + nameParent2 + ";" + billAddress + ";" + phoneNumber + ";" + nameChildren + ";" + password;
}
}

View File

@ -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