81 lines
2.1 KiB
Java
81 lines
2.1 KiB
Java
import java.awt.*;
|
|
import java.io.*;
|
|
|
|
public class Authentification {
|
|
|
|
private ABR dictionnaire;
|
|
|
|
public Authentification() {
|
|
this.dictionnaire = new ABR();
|
|
}
|
|
|
|
public void ajouter(String username, String password) {
|
|
if (this.dictionnaire.estPresent(username)) {
|
|
System.out.println("L'utilisateur '" + username + "' existe déjà.");
|
|
} else {
|
|
this.dictionnaire.ajouterUtilisateur(username, password);
|
|
System.out.println("Utilisateur ajouté.");
|
|
}
|
|
System.out.println(this.dictionnaire);
|
|
}
|
|
|
|
public void authentifier(String username, String password) {
|
|
if (!this.dictionnaire.estPresent(username)) {
|
|
System.out.println("L'utilisateur '" + username + "' n'existe pas.");
|
|
} else if (!this.dictionnaire.authentifier(username, password)) {
|
|
System.out.println("Le mot de passe est incorrect.");
|
|
} else {
|
|
System.out.println("L'utilisateur '" + username + "' est authentifié.");
|
|
}
|
|
System.out.println(this.dictionnaire);
|
|
}
|
|
|
|
public void supprimer(String username) {
|
|
if (!this.dictionnaire.estPresent(username)) {
|
|
System.out.println("L'utilisateur '" + username + "' n'existe pas.");
|
|
} else {
|
|
this.dictionnaire.supprimer(username);
|
|
System.out.println("L'utilisateur '" + username + "' a été supprimé");
|
|
}
|
|
System.out.println(this.dictionnaire);
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
Authentification auth = new Authentification();
|
|
|
|
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
|
|
|
|
String input = "";
|
|
|
|
while (!input.equals("quit")) {
|
|
|
|
System.out.print("> ");
|
|
|
|
try {
|
|
|
|
String[] ligne = console.readLine().split(" ");
|
|
input = ligne[0];
|
|
|
|
|
|
|
|
if (input.equals("add")) {
|
|
auth.ajouter(ligne[1], ligne[2]);
|
|
} else if (input.equals("auth")) {
|
|
auth.authentifier(ligne[1], ligne[2]);
|
|
} else if (input.equals("del")) {
|
|
auth.supprimer(ligne[1]);
|
|
} else. if (input.equals("quit")) {
|
|
|
|
} else {
|
|
System.out.println("Commande non reconnue.");
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
System.err.println("Erreur de la console");
|
|
} catch (ArrayIndexOutOfBoundsException e1) {
|
|
System.err.println("Erreur d'arguments");
|
|
}
|
|
}
|
|
}
|
|
|
|
} |