From e8e2d06c52028a4dc210d9b5160a27a5c38611a8 Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Fri, 6 Jan 2023 15:21:57 +0100 Subject: [PATCH 1/2] =?UTF-8?q?fonction=20pour=20savoir=20si=20l'utilisate?= =?UTF-8?q?ur=20existe=20ou=20non=20est=20comment=C3=A9es=20et=20test?= =?UTF-8?q?=C3=A9es=20(fonctionnelle=20donc)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- header/sae.h | 3 ++- source/main.c | 3 +-- source/sae.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/header/sae.h b/header/sae.h index bb9f860..d24ed19 100644 --- a/header/sae.h +++ b/header/sae.h @@ -91,7 +91,8 @@ typedef struct void testJean(void); void Globale(void); -Log * chargementLog(char * nomFichier); +Log * chargementLog(char * nomFichier, int * nbLog); +int existeUtilisateur(char * utilisateur, int * indice, Log * tLog, int nbLog); //void menuVisiteur(VilleIut *villeIut, int nbVilles); void menuVisiteur(Log * tLog); int afficherMenuVisiteur(void); diff --git a/source/main.c b/source/main.c index 865a1fe..22969bf 100644 --- a/source/main.c +++ b/source/main.c @@ -9,9 +9,8 @@ int main(void) color #endif - //Globale(); + Globale(); - testJean(); return 0; diff --git a/source/sae.c b/source/sae.c index 78d0cfa..105c89a 100644 --- a/source/sae.c +++ b/source/sae.c @@ -15,9 +15,10 @@ void Globale(void) { Log * tLog; + int nbLog; //Chargement des fichiers - tLog = chargementLog("../donnees/log.don"); + tLog = chargementLog("../donnees/log.don", &nbLog); //Appel du menu visiteur menuVisiteur(tLog); @@ -30,14 +31,14 @@ void Globale(void) * @param nomFichier [CHAINE DE CARACTERE] Le nom du fichier à charger * @return Log* [TABLEAU DYNAMIQUE DE STRUCTURE] Le tableau de structures Log contenant les logs du fichier */ -Log * chargementLog(char * nomFichier) +Log * chargementLog(char * nomFichier, int * nbLog) { FILE * fichier; Log * tLog; Log * tAnnexe; int nbLogMax; - int nbLog; + int i; fichier = fopen(nomFichier, "r"); @@ -74,6 +75,7 @@ Log * chargementLog(char * nomFichier) i++; } + *nbLog = i; return tLog; } @@ -189,15 +191,52 @@ int choixMenuVisiteur(void) */ void seConnecterTest(void) { + Log * tLog; + char mdp[30], utilisateur[30]; + int indice, existe, nbLog; + + nbLog = 0; + tLog = chargementLog("../donnees/log.don", &nbLog); //TEMP + banniereConnection(); // Affichage saisieNomUtilisateur(utilisateur); // Récupération du nom d'utilisateur + existe = existeUtilisateur(utilisateur, &indice, tLog, nbLog); + + if (existe) + printf("True\n"); + else + printf("False\n"); + saisieMdp(mdp); // Récupération du mot de passe } +/** + * @brief Vérifie si un utilisateur existe dans le tableau de structures de log. + * + * @param utilisateur [CHAINE DE CARACTERES] Le nom de l'utilisateur à rechercher. + * @param indice [POINTEUR] Pointeur vers un entier qui sera modifié pour stocker l'indice de l'utilisateur s'il est trouvé. + * @param tLog [TABLEAU] Tableau de structures de log. + * @param nbLog [Taille Logique] Nombre d'éléments dans le tableau de structures de log. + * + * @return int 1 --> l'utilisateur existe | 0 --> l'utilisateur n'existe pas + */ +int existeUtilisateur(char * utilisateur, int * indice, Log * tLog, int nbLog) +{ + for (int i = 0 ; i < nbLog ; i++) + { + if (strcmp(tLog[i].utilisateur,utilisateur) == 0) + { + *indice = i; + return 1; + } + } + return 0; +} + /** * @brief Affichage de la bannière de connexion. */ From 97fedd467c2dbe08c0dc032fc07c5114b67b98ce Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Fri, 6 Jan 2023 15:36:00 +0100 Subject: [PATCH 2/2] Fonction de verification du mot de passe mise en place --- header/sae.h | 1 + source/sae.c | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/header/sae.h b/header/sae.h index d24ed19..fa0f7e2 100644 --- a/header/sae.h +++ b/header/sae.h @@ -93,6 +93,7 @@ void testJean(void); void Globale(void); Log * chargementLog(char * nomFichier, int * nbLog); int existeUtilisateur(char * utilisateur, int * indice, Log * tLog, int nbLog); +int mdpValide(char * mdp, int indice, Log * tLog); //void menuVisiteur(VilleIut *villeIut, int nbVilles); void menuVisiteur(Log * tLog); int afficherMenuVisiteur(void); diff --git a/source/sae.c b/source/sae.c index 105c89a..1675183 100644 --- a/source/sae.c +++ b/source/sae.c @@ -195,7 +195,7 @@ void seConnecterTest(void) char mdp[30], utilisateur[30]; - int indice, existe, nbLog; + int indice, existe, nbLog, valide; nbLog = 0; tLog = chargementLog("../donnees/log.don", &nbLog); //TEMP @@ -205,13 +205,10 @@ void seConnecterTest(void) saisieNomUtilisateur(utilisateur); // Récupération du nom d'utilisateur existe = existeUtilisateur(utilisateur, &indice, tLog, nbLog); - - if (existe) - printf("True\n"); - else - printf("False\n"); - + saisieMdp(mdp); // Récupération du mot de passe + + valide = mdpValide(mdp, indice, tLog); } /** @@ -237,6 +234,20 @@ int existeUtilisateur(char * utilisateur, int * indice, Log * tLog, int nbLog) return 0; } +/** + * @brief Valide si le mot de passe donné correspond au mot de passe enregistré dans la structure de log. + * + * @param mdp [CHAINE DE CARACTERES] Le mot de passe à valider. + * @param indice L'indice de la structure de log à utiliser pour la vérification. + * @param tLog [TABLEAU] Le tableau de structures de log. + * + * @return int 1 --> le mot de passe correspond | 0 --> le mot de passe ne correspond pas + */ +int mdpValide(char * mdp, int indice, Log * tLog) +{ + if (strcmp(tLog[indice].mdp, mdp) == 0) return 1; + else return 0; +} /** * @brief Affichage de la bannière de connexion. */