From 99b0dcac138f0593da1cc338acc0933d4a19c552 Mon Sep 17 00:00:00 2001 From: Nicolas BLONDEAU Date: Tue, 2 May 2023 16:31:19 +0200 Subject: [PATCH] =?UTF-8?q?Attention=20erreur,=20mais=20recherche=20impl?= =?UTF-8?q?=C3=A9ment=C3=A9e,=20v=C3=A9rification=20du=20mot=20de=20passe?= =?UTF-8?q?=20s=C3=A9curis=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Console/Program.cs | 119 +++++++++++++++++++++++++++++--------------- Modèle/Stub.cs | 8 +-- Modèle/User.cs | 20 ++++++-- Modèle/UserBase.cs | 2 +- 4 files changed, 98 insertions(+), 51 deletions(-) diff --git a/Console/Program.cs b/Console/Program.cs index bfd49d5..fac0e86 100644 --- a/Console/Program.cs +++ b/Console/Program.cs @@ -40,36 +40,39 @@ int menuAccueil(){ Console.WriteLine("Menu - Connexion / Inscription"); Console.WriteLine("\t1 - Connexion\n\t2 - Inscription\n\t3 - Connexion plus tard\n\t4 - Fermer\n"); choix = Console.ReadLine(); - if (choix == "1") + while(choix != null) { - Console.Clear(); - Console.WriteLine("Choix 1"); - menuConnexion(); - return 1; - } - else if (choix == "2") - { - Console.Clear(); - Console.WriteLine("Choix 2"); - return 2; - } - else if (choix == "3") - { - Console.Clear(); - Console.WriteLine("Choix 3"); - monsterPage(); - return 3; - } - else if (choix == "4") - { - Console.Clear(); - Console.WriteLine("Exit"); - return 4; - } - else - { - // Si l'utilisateur entre autre chose que 1, 2, 3 ou 4 - Console.WriteLine("Écris un nombre compris entre 1 et 3"); + if (choix == "1") + { + Console.Clear(); + Console.WriteLine("Choix 1"); + menuConnexion(); + return 1; + } + else if (choix == "2") + { + Console.Clear(); + Console.WriteLine("Choix 2"); + return 2; + } + else if (choix == "3") + { + Console.Clear(); + Console.WriteLine("Choix 3"); + monsterPage(); + return 3; + } + else if (choix == "4") + { + Console.Clear(); + Console.WriteLine("Exit"); + return 4; + } + else + { + // Si l'utilisateur entre autre chose que 1, 2, 3 ou 4 + Console.WriteLine("Écris un nombre compris entre 1 et 3, ou juste tape sur la touche Entrée pour quitter."); + } } return 0; } @@ -111,8 +114,21 @@ int menuConnexion() { string? id; string? psswd; - Console.WriteLine("Identifiant : "); - id = Console.ReadLine(); + int ret = 0; + while ( ret != 0 ) + { + Console.WriteLine("Identifiant : "); + id = Console.ReadLine(); + if (!string.IsNullOrEmpty(id)) + { + ret = 1; + Console.Clear(); + } else + { + ret = 0; + } + } + Console.WriteLine("Mot de passe : "); psswd = ReadPassword(); int nbRetries = 0; @@ -146,8 +162,36 @@ int monsterPage() choix = Console.ReadLine(); if ( choix == "1") { - //Tant que lecture de l'entrée != JE VEUX SORTIR - //while(Console.ReadLine) + List m = new List(); + Console.Clear (); + ConsoleKeyInfo carac = Console.ReadKey(true); ; + string listCarac = ""; + while (carac.Key != ConsoleKey.Enter) + { + + if (carac.Key != ConsoleKey.Backspace) + { + listCarac += carac.KeyChar; + } + else if (carac.Key == ConsoleKey.Backspace) + { + if (!string.IsNullOrEmpty(listCarac)) + { + listCarac = listCarac.Remove(listCarac.Length - 1, 1); + } + } + Console.Clear (); + Console.Write(listCarac); + Console.WriteLine(); + Console.WriteLine(); + m = monsterBase.search(listCarac.ToString(), monsterBase); + foreach (Monstre mnstr in m) + { + Console.WriteLine($"{mnstr.Name} a été trouvé!"); + } + carac = Console.ReadKey(true); + } + return 1; } @@ -158,11 +202,4 @@ int monsterPage() return 0; } -//int codeRetour = menuAccueil(); - - -List m = monsterBase.search("o", monsterBase); -foreach ( Monstre mnstr in m) -{ - Console.WriteLine($"{mnstr.Name} a été trouvé!"); -} \ No newline at end of file +int codeRetour = menuAccueil(); \ No newline at end of file diff --git a/Modèle/Stub.cs b/Modèle/Stub.cs index 51157bc..1d491e9 100644 --- a/Modèle/Stub.cs +++ b/Modèle/Stub.cs @@ -17,10 +17,10 @@ namespace Modèle public List loadUsers() ///CHANGER VISIBILITEE, CAR PAS BIEN DE LAISSER A TOUT LE MONDE { List lu = new List(); - lu.Add(new User("DedeDu42", "dede", "dodo", "mdp")); - lu.Add(new User("Moi", "Monchanin", "Liam", "feur")); - lu.Add(new User("Nikoala", "Blondeau", "Nicolas", "niblondeau")); - lu.Add(new User("Yadoumir", "Doumir", "Yannis", "mdp")); + lu.Add(new User("DedeDu42", "dede", "dodo", "mdp", new List { })); + lu.Add(new User("Moi", "Monchanin", "Liam", "feur", new List { })); + lu.Add(new User("Nikoala", "Blondeau", "Nicolas", "niblondeau", new List { })); + lu.Add(new User("Yadoumir", "Doumir", "Yannis", "mdp", new List { })); return lu; } diff --git a/Modèle/User.cs b/Modèle/User.cs index 2274212..2418b45 100644 --- a/Modèle/User.cs +++ b/Modèle/User.cs @@ -14,17 +14,27 @@ namespace Modèle public class User { public string Pseudo { get; private set; } - private string Nom { get; } - private string Prenom { get; } - public string Mdp { get; private set; } + private string Nom { get; set; } + private string Prenom { get; set; } + private string Mdp { get; set; } + private List monstresDejaVu { get; set; } - - public User(string pseudo, string nom, string prenom, string mdp) + public User(string pseudo, string nom, string prenom, string mdp, List monstresVus) { Pseudo = pseudo; Nom = nom; Prenom = prenom; Mdp = mdp; + monstresDejaVu = monstresVus; + } + + public bool verifyPssw(string pssw) + { + if(pssw.Equals(Mdp)) + { + return true; + } + return false; } } } diff --git a/Modèle/UserBase.cs b/Modèle/UserBase.cs index 4e82a07..4d2c0c1 100644 --- a/Modèle/UserBase.cs +++ b/Modèle/UserBase.cs @@ -43,7 +43,7 @@ namespace Modèle } foreach (User u in ListUsers) { - if (username.Equals(u.Pseudo) && password.Equals(u.Mdp)) + if (username.Equals(u.Pseudo) && u.verifyPssw(password)) { return 5; }