login
This commit is contained in:
parent
715a6fa94a
commit
6b6aecffda
66
src/Datei.java
Normal file
66
src/Datei.java
Normal file
@ -0,0 +1,66 @@
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
public class Datei {
|
||||
private String dataName;
|
||||
|
||||
public Datei(String dataName) {
|
||||
this.dataName = dataName;
|
||||
}
|
||||
|
||||
public User[] laden() {
|
||||
|
||||
Path pfad = Paths.get(dataName);
|
||||
|
||||
|
||||
try {
|
||||
List<String> zeilen = Files.readAllLines(pfad);
|
||||
User[] userListe = new User[zeilen.size()];
|
||||
|
||||
for (int i = 0; i < zeilen.size(); i++) {
|
||||
|
||||
String[] teile = zeilen.get(i).split(":");
|
||||
|
||||
String nameParent1 = teile[0];
|
||||
String nameParent2 = teile[1];
|
||||
String billAddress = teile[2];
|
||||
String phonenumber = teile[3];
|
||||
String nameChildren = teile[4];
|
||||
String password = teile[5];
|
||||
|
||||
|
||||
userListe[i] = new User(nameParent1, nameParent2, billAddress, phonenumber, nameChildren, password);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return userListe;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// public void speichern(Farbe[] farben, String dateiName) {
|
||||
//
|
||||
// Path pfad = Paths.get(dateiname);
|
||||
//
|
||||
// List<String> zeilen = new ArrayList<>();
|
||||
// for (Farbe farbe : farben) {
|
||||
// zeilen.add(farbe.formatieren());
|
||||
//
|
||||
// }
|
||||
// try {
|
||||
// Files.write(pfad, zeilen);
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
|
||||
// }
|
||||
|
||||
}
|
@ -1,14 +1,58 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**The class Execute is the executen file for the whole programm.
|
||||
/**
|
||||
* The class Execute is the executen file for the whole programm.
|
||||
*/
|
||||
public class Execute {
|
||||
public static void main(String[] args) {
|
||||
ArrayList<String> data = GeneralMethods.readData("test.csv");
|
||||
Datei datei = new Datei("users.txt");
|
||||
User[] user = datei.laden();
|
||||
|
||||
for(String d : data){
|
||||
System.out.println(d);
|
||||
for (User user1 : user) {
|
||||
System.out.println(user1);
|
||||
}
|
||||
System.out.println();
|
||||
System.out.println("\t\t\tANMELDUNG");
|
||||
int i = 0;
|
||||
Scanner leser = new Scanner(System.in);
|
||||
while (true) {
|
||||
|
||||
|
||||
System.out.print("Name: ");
|
||||
boolean error = false;
|
||||
String name = leser.nextLine();
|
||||
if(name.isEmpty()){
|
||||
error = true;
|
||||
}
|
||||
System.out.print("Passwort: ");
|
||||
String password = leser.nextLine();
|
||||
if(password.isEmpty()){
|
||||
error = true;
|
||||
}
|
||||
|
||||
|
||||
for (User user1 : user) {
|
||||
if (!error) {
|
||||
if (user1.getPassword().equals(password) && user1.getPhonenumber().equals(name)) {
|
||||
System.out.println();
|
||||
System.out.println("Herzlich Willkommen " + user1.getNameParent1() + " und " + user1.getNameParent2() + ", Ihr Login war erfolgreich!");
|
||||
i++;
|
||||
break;
|
||||
|
||||
} else if (!(user1.getPassword().equals(password) && user1.getPhonenumber().equals(name))) {
|
||||
System.out.println("Login fehlgeschlagen. Versuchen Sie es erneut.");
|
||||
break;
|
||||
}
|
||||
|
||||
}else{
|
||||
System.out.println("Bitte Anmeldedaten angeben.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
GeneralMethods.writeData("test2.csv",data);
|
||||
}
|
||||
}
|
||||
|
45
src/User.java
Normal file
45
src/User.java
Normal file
@ -0,0 +1,45 @@
|
||||
public class User {
|
||||
private String nameParent1;
|
||||
private String nameParent2;
|
||||
private String billAddress;
|
||||
private String phonenumber;
|
||||
private String nameChildren;
|
||||
private String password;
|
||||
|
||||
public User(String nameParent1, String nameParent2, String billAddress, String phonenumber, String nameChildren, String password) {
|
||||
this.nameParent1 = nameParent1;
|
||||
this.nameParent2 = nameParent2;
|
||||
this.billAddress = billAddress;
|
||||
this.phonenumber = phonenumber;
|
||||
this.nameChildren = nameChildren;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getPhonenumber() {
|
||||
return phonenumber;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getNameParent1() {
|
||||
return nameParent1;
|
||||
}
|
||||
|
||||
public String getNameParent2() {
|
||||
return nameParent2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"nameParent1='" + nameParent1 + '\'' +
|
||||
", nameParent2='" + nameParent2 + '\'' +
|
||||
", billAddress='" + billAddress + '\'' +
|
||||
", phonenumber='" + phonenumber + '\'' +
|
||||
", nameChildren='" + nameChildren + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user