diff --git a/header/sae.h b/header/sae.h index af94b29..7914192 100644 --- a/header/sae.h +++ b/header/sae.h @@ -91,7 +91,9 @@ 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); +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/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..1675183 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,63 @@ int choixMenuVisiteur(void) */ void seConnecterTest(void) { + Log * tLog; + char mdp[30], utilisateur[30]; + int indice, existe, nbLog, valide; + + 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); + saisieMdp(mdp); // Récupération du mot de passe + + valide = mdpValide(mdp, indice, tLog); } +/** + * @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 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. */