ça marche ENFIN, affichage du menu, partie connexion fonctionnelle, mot de passe caché, création du stub, ajout de la UserBase et tout est fonctionnelle YESSSS

pull/32/head
Nicolas BLONDEAU 2 years ago
parent e3634edb86
commit 54ce10925f

@ -3,6 +3,11 @@
using Modèle;
using System;
using System.Reflection.PortableExecutable;
///Déclaration du STUB
UserBase ub = new UserBase();
/*
void testMonstre()
{
//Création non permanente d'une liste de caractéristiques (pour tests) -> PEUT-ÊTRE EN FAIRE UNE CLASSE PLUS TARD???
@ -26,37 +31,97 @@ void testMonstre()
Console.WriteLine();
Monstre monstre2 = new Monstre(423, "Mouton", "Je suis un animal présent dans la campagne.", charact, appear);
Console.WriteLine(monstre2.IntroduceTest());
}
}*/
void testUser(){
// User
string pseudo;
string mdp;
User Dede = new User("DedeDu42", "dede", "dodo", "mdp");
Dede.ListUsers.Add(Dede);
Console.WriteLine("Veuillez Saisir votre pseudo");
pseudo = Console.ReadLine();
Console.WriteLine("Veuillez Saisir votre mdp");
mdp = Console.ReadLine();
if (Dede.testConnexion(pseudo, mdp) == 0)
{
Console.WriteLine("Welcome home");
}
//FAILLE DE SECU -> Ne pas dire si c'est le pseudo ou le mot de passe
if (Dede.testConnexion(pseudo, mdp) == 1) //Ne passe jamais dans cette condition -> Directement dans le cas ou testConnexion = -1
int menuPrincipal(){
string? choix;
Console.WriteLine("Menu - Connexion / Inscription");
Console.WriteLine("\t1 - Connexion\n\t2 - Inscription\n\t3 - Connexion plus tard\n");
choix = Console.ReadLine();
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.WriteLine("Pseudo incorrect");
Console.Clear();
Console.WriteLine("Choix 3");
return 3;
} else
{
Console.WriteLine("Écris un nombre compris entre 1 et 3");
}
if (Dede.testConnexion(pseudo, mdp) == 2)
return 0;
}
string ReadPassword()
{
string psswrd = "";
ConsoleKeyInfo info = Console.ReadKey(true);
while (info.Key != ConsoleKey.Enter)
{
Console.WriteLine("Mot de passe incorrect");
if (info.Key != ConsoleKey.Backspace)
{
Console.Write("*");
psswrd += info.KeyChar;
}
else if (info.Key == ConsoleKey.Backspace)
{
if (!string.IsNullOrEmpty(psswrd))
{
// Supprime un élément de la liste de char de psswrd
psswrd = psswrd.Substring(0, psswrd.Length - 1);
// get the location of the cursor
int pos = Console.CursorLeft;
// move the cursor to the left by one character
Console.SetCursorPosition(pos - 1, Console.CursorTop);
// replace it with space
Console.Write(" ");
// move the cursor to the left by one character again
Console.SetCursorPosition(pos - 1, Console.CursorTop);
}
}
info = Console.ReadKey(true);
}
if (Dede.testConnexion(pseudo, mdp) == -1)
// Ajoute un alinéa parce que l'utlisateur a validé
Console.WriteLine();
return psswrd;
}
int menuConnexion()
{
string? id;
string? psswd;
Console.WriteLine("Identifiant : ");
id = Console.ReadLine();
Console.WriteLine("Mot de passe : ");
psswd = ReadPassword();
int nbRetries = 0;
int exists = ub.checkIfExists(id, psswd);
while (exists == 0)
{
Console.WriteLine("...");
if(nbRetries >= 3)
{
return -1;
}
Console.Clear();
Console.WriteLine("Erreur, identifiant ou mot de passe incorrect.");
nbRetries++;
Console.WriteLine("");
Console.WriteLine("Identifiant : ");
id = Console.ReadLine();
Console.WriteLine("Mot de passe : ");
psswd = ReadPassword();
exists = ub.checkIfExists(id, psswd);
}
return 0;
}
testMonstre();
testUser();
int codeRetour = menuPrincipal();

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
namespace Modèle
{
public class Stub
{
public Stub() { }
public List<User> loadUsers() ///CHANGER VISIBILITEE, CAR PAS BIEN DE LAISSER A TOUT LE MONDE
{
List<User> lu = new List<User>();
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"));
return lu;
}
}
}

@ -12,7 +12,6 @@ namespace Modèle
private string Nom { get; }
private string Prenom { get; }
public string Mdp { get; private set; }
public List<User> ListUsers { get; private set; } = new List<User>();
public User(string pseudo, string nom, string prenom, string mdp)
@ -22,28 +21,5 @@ namespace Modèle
Prenom = prenom;
Mdp = mdp;
}
public int testConnexion(string pseudo, string mdp)
{
foreach (User i in ListUsers)
{
if (i.Pseudo.Equals(pseudo) && i.Mdp.Equals(mdp))
{
return 0;
}
else
{
if (i.Pseudo != pseudo && i.Mdp.Equals(mdp))
{
return 1;
}
if (i.Pseudo.Equals(pseudo) && i.Mdp != mdp)
{
return 2;
}
}
}
return -1;
}
}
}

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Modèle
{
public class UserBase
{
private List<User> users;
public List<User> ListUsers
{
get
{
return users;
}
private set
{
users = value;
}
}
public UserBase()
{
ListUsers = new Stub().loadUsers();
}
public int checkIfExists(string username, string password)
{
foreach (User u in ListUsers)
{
if(username.Equals(u.Pseudo) && password.Equals(u.Mdp))
{
Console.WriteLine($"Bienvenue, {u.Pseudo}, vous venez de vous connecter!");
return 1;
}
}
return 0;
}
}
}
Loading…
Cancel
Save