@ -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 ( ) ;