Login funktioniert jetzt
This commit is contained in:
		@@ -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<String, String> 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.");
 | 
			
		||||
 
 | 
			
		||||
@@ -61,31 +61,19 @@ 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
 | 
			
		||||
    protected void OnSignInButton(ActionEvent event) throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        LoginDatei file = new LoginDatei("user.txt");
 | 
			
		||||
        HashMap<String, String> 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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										4
									
								
								user.txt
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user