62 lines
2.4 KiB
Java
62 lines
2.4 KiB
Java
import java.io.BufferedReader;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.TreeMap;
|
|
|
|
public class Authentification {
|
|
public static void main(String[] args) {
|
|
Map<String, String> loginMap = new TreeMap<>();
|
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
|
try {
|
|
while (true) {
|
|
String command = br.readLine();
|
|
String[] cargs = command.split(" ");
|
|
|
|
switch (cargs[0].toLowerCase()) {
|
|
case "add":
|
|
if (loginMap.containsKey(cargs[1])) {
|
|
System.err.println("Utilisateur \"" + cargs[1] + "\" déjà existant.");
|
|
} else {
|
|
loginMap.put(cargs[1], cargs[2]);
|
|
System.out.println("Utilisateur \"" + cargs[1] + "\" ajouté.");
|
|
}
|
|
break;
|
|
|
|
case "auth":
|
|
if (loginMap.containsKey(cargs[1])) {
|
|
if (loginMap.get(cargs[1]).compareTo(cargs[2]) == 0) {
|
|
System.out.println("Utilisateur \"" + cargs[1] + "\" reconnu.");
|
|
} else {
|
|
System.err.println("Utilisateur \"" + cargs[1] + "\" non reconnu.");
|
|
}
|
|
} else {
|
|
System.err.println("Utilisateur \"" + cargs[1] + "\" non reconnu.");
|
|
}
|
|
break;
|
|
|
|
case "del":
|
|
if (loginMap.containsKey(cargs[1])) {
|
|
loginMap.remove(cargs[1]);
|
|
System.out.println("Utilisateur \"" + cargs[1] + "\" retiré.");
|
|
} else {
|
|
System.err.println("Utilisateur \"" + cargs[1] + "\" non reconnu.");
|
|
}
|
|
break;
|
|
|
|
case "quit":
|
|
System.out.println("Au revoir");
|
|
return;
|
|
|
|
default:
|
|
System.out.println("Commande inconnue");
|
|
}
|
|
}
|
|
} catch (IOException e) {
|
|
System.err.println(e);
|
|
}
|
|
}
|
|
}
|