From e7ff9418aa08e0f28b21a5c274b397b6a81c266d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20LAVERGNE?= Date: Wed, 8 Nov 2023 00:02:43 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20des=20mots=20de=20passe=20et=20du=20cry?= =?UTF-8?q?ptage/d=C3=A9cryptage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/login.c | 45 +++++++++++++++++++++++++++++++++++++-------- src/main.c | 6 +++--- src/main.h | 16 ++++++++++------ src/passwd.c | 36 ++++++++++++++++++++++++++++++++++++ src/traitement.c | 21 +++++++++++---------- 5 files changed, 97 insertions(+), 27 deletions(-) create mode 100644 src/passwd.c diff --git a/src/login.c b/src/login.c index 9d6119e..7934d00 100644 --- a/src/login.c +++ b/src/login.c @@ -7,9 +7,9 @@ * @param tlog: Taille logique des Tableaux * @return Est Admin ? (1 > Oui, 0 > Non, -1 > Quitter) */ -int login(int clientID[], int isAdmin[], int tlog) +int login(int clientID[], int clientPassword[], int isAdmin[], int tlog) { - int id, index, found, tentative=3; + int id, password, index, found, tentative=3; printf("Entrez votre identifiant: "); scanf("%d%*c", &id); while (id < 0) @@ -18,7 +18,6 @@ int login(int clientID[], int isAdmin[], int tlog) scanf("%d%*c", &id); } index = searchTab(clientID, id, tlog, &found); - printf("%d",found); while(found == 0) { printf("Erreur, l'identifiant n'existe pas, entrez votre identifiant: "); @@ -34,21 +33,40 @@ int login(int clientID[], int isAdmin[], int tlog) printf("Nombre de tentatives dépassé, retour au menu principal.\n"); return -1; } + printf("Il vous reste %d tentatives.\n", tentative); + index = searchTab(clientID, id, tlog, &found); } - if (isAdmin[index] == 1) + + printf("Entrez votre mot de passe: "); + scanf("%d%*c", &password); + while (password < 0) { - return 1; + printf("Erreur, le mot de passe doit être positif, entrez votre mot de passe: "); + scanf("%d%*c", &password); + } + + if (password == decrypt(clientPassword[index])) + { + if (isAdmin[index] == 1) + { + return 1; + } + else + { + return 0; + } } else { - return 0; + printf("Erreur, le mot de passe est incorrect.\n"); + return -1; } } -int signup(int clientID[], float cagnotte[], int suspended[], int isAdmin[], int *tlog) +int signup(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int *tlog) { - int id, index, found; + int id, password, index, found; printf("Entrez votre identifiant: "); scanf("%d%*c", &id); while (id < 0) @@ -67,6 +85,17 @@ int signup(int clientID[], float cagnotte[], int suspended[], int isAdmin[], int } index = searchTab(clientID, id, *tlog, &found); } + + printf("Entrez votre mot de passe: "); + scanf("%d%*c", &password); + while (password < 0) + { + printf("Erreur, le mot de passe doit être positif, entrez votre mot de passe: "); + scanf("%d%*c", &password); + } + + clientPassword[*tlog] = encrypt(password); + clientID[*tlog] = id; cagnotte[*tlog] = 0; suspended[*tlog] = 0; diff --git a/src/main.c b/src/main.c index 70d4f03..6b49f22 100644 --- a/src/main.c +++ b/src/main.c @@ -53,7 +53,7 @@ void global(void) */ // Déclaration des variables int tLogArticle, tLogClient, choice, status, currentUser; - int reference[tmaxArticles], clientID[tmaxClients], suspended[tmaxClients], isAdmin[tmaxClients]; + int reference[tmaxArticles], clientID[tmaxClients], clientPassword[tmaxClients], suspended[tmaxClients], isAdmin[tmaxClients]; float weight[tmaxArticles], volume[tmaxArticles], unitPrice[tmaxArticles], cagnotte[tmaxClients]; // Chargement de toute les données chargeDonnees(&tLogArticle, &tLogClient, reference, weight, volume, unitPrice, clientID, cagnotte, suspended, isAdmin); @@ -65,7 +65,7 @@ void global(void) switch (choice) { case 1: - status = login(clientID, isAdmin, tLogClient); + status = login(clientID, clientPassword, isAdmin, tLogClient); if(status == 1) { //TODO > Menu Admin @@ -83,7 +83,7 @@ void global(void) } break; case 2: - status = signup(clientID, cagnotte, suspended, isAdmin, &tLogClient); + status = signup(clientID, clientPassword, cagnotte, suspended, isAdmin, &tLogClient); if(status == 0) { printf("Inscription réussie.\nRetour au menu principal...\n"); diff --git a/src/main.h b/src/main.h index 9d27a05..ddb70c3 100644 --- a/src/main.h +++ b/src/main.h @@ -19,13 +19,13 @@ void debugHandling(int code); void debugMenu(int tabReference[], float tabWeight[], float tabVolume[], float unitPrice[], int clientID[], float cagnotte[], int suspended[], int isAdmin[], int tlogArticle, int tlogClient); //! TRAITEMENT DES FICHIERS -void chargeDonnees(int *tLogArticle, int *tLogClient,int reference[], float weight[], float volume[], float unitPrice[], int clientID[], float cagnotte[], int suspended[], int isAdmin[]); +void chargeDonnees(int *tLogArticle, int *tLogClient,int reference[], float weight[], float volume[], float unitPrice[], int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[]); int chargeArticles(int reference[], float weight[], float volume[], float unitPrice[]); -int chargeClients(int clientID[], float cagnotte[], int suspended[], int isAdmin[]); +int chargeClients(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[]); -void sauvegardeDonnees(int tLogArticle, int tLogClient, int reference[], float weight[], float volume[], float unitPrice[], int clientID[], float cagnotte[], int isAdmin[], int suspended[]); +void sauvegardeDonnees(int tLogArticle, int tLogClient, int reference[], float weight[], float volume[], float unitPrice[], int clientID[], int clientPassword[], float cagnotte[], int isAdmin[], int suspended[]); void sauvegardeArticles(int reference[], float weight[], float volume[], float unitPrice[], int tLogArticle); -void sauvegardeClients(int clientID[], float cagnotte[], int suspended[], int isAdmin[], int tLogClient); +void sauvegardeClients(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int tLogClient); //! GESTION CLIENTS int inputClient(int clientID[], float cagnotte[], int suspended[], int isAdmin[], int *tlog); @@ -54,5 +54,9 @@ int reinit_basket(int tlog_basket); int basket_del_article( int basket_tab_ref[], int basket_tab_qte[], int tlog_basket); //! LOGIN -int login(int clientID[], int isAdmin[], int tlog); -int signup(int clientID[], float cagnotte[], int suspended[], int isAdmin[], int *tlog); \ No newline at end of file +int login(int clientID[], int clientPassword[], int isAdmin[], int tlog); +int signup(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int *tlog); + +//! MOT DE PASSE +int encrypt(int password); +int decrypt(int password); \ No newline at end of file diff --git a/src/passwd.c b/src/passwd.c new file mode 100644 index 0000000..7c4dc22 --- /dev/null +++ b/src/passwd.c @@ -0,0 +1,36 @@ +/** + * @file passwd.c + * @brief Gestion des mots de passe +*/ + +#include "main.h" + +/** + * @brief Encryption d'un mot de passe avec la méthode de César + * @param password: Mot de passe à encrypter + * @return int: Mot de passe encrypté +*/ +int encrypt(int password) +{ + int i; + for (i=0; i