Ajout des mots de passe et du cryptage/décryptage

doc
Rémi LAVERGNE 1 year ago
parent 9cd95e4b33
commit e7ff9418aa
No known key found for this signature in database
GPG Key ID: 8861D8A4AD21A032

@ -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,8 +33,21 @@ 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);
}
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);
}
if (password == decrypt(clientPassword[index]))
{
if (isAdmin[index] == 1)
{
return 1;
@ -44,11 +56,17 @@ int login(int clientID[], int isAdmin[], int tlog)
{
return 0;
}
}
else
{
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;

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

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

@ -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<len(password); i++)
{
password[i] = password[i] + 3*i; // On décale chaque caractère du mot de passe de 3*i
}
return password;
}
/**
* @brief Décryption d'un mot de passe
* @param password: Mot de passe à décrypter
* @return int: Mot de passe décrypté
*/
int decrypt(int password)
{
int i;
for (i=0; i<len(password); i++)
{
password[i] = password[i] - 3*i; // On décale chaque caractère du mot de passe de 3*i
}
return password;
}

@ -5,7 +5,7 @@
#include "main.h"
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[])
{
/*
Chargement des données des articles et clients de fichiers vers des tableaux
@ -21,7 +21,7 @@ void chargeDonnees(int *tLogArticle, int *tLogClient,int reference[], float weig
+param suspended: tableau de l'état du compte des clients
*/
*tLogArticle = chargeArticles(reference, weight, volume, unitPrice);
*tLogClient = chargeClients(clientID, cagnotte, suspended, isAdmin);
*tLogClient = chargeClients(clientID, clientPassword, cagnotte, suspended, isAdmin);
}
int chargeArticles(int reference[], float weight[], float volume[], float unitPrice[])
@ -77,7 +77,7 @@ int chargeArticles(int reference[], float weight[], float volume[], float unitPr
return tL;
}
int chargeClients(int clientID[], float cagnotte[], int suspended[], int isAdmin[])
int chargeClients(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[])
{
/*
Chargement des données des clients d'un fichier vers des tableaux
@ -102,10 +102,10 @@ int chargeClients(int clientID[], float cagnotte[], int suspended[], int isAdmin
exit(1);
}
int id, sus, tL=0, adm;
int id, passwd, sus, tL=0, adm;
float cag;
fscanf(client, "%d %f %d %d", &id, &cag, &sus, &adm);
fscanf(client, "%d %d %f %d %d", &id, &passwd, &cag, &sus, &adm);
while(!feof(client))
{
if(tL == tmaxArticles)
@ -115,20 +115,21 @@ int chargeClients(int clientID[], float cagnotte[], int suspended[], int isAdmin
}
clientID[tL] = id;
clientPassword[tL] = passwd;
cagnotte[tL] = cag;
suspended[tL] = sus;
isAdmin[tL] = adm;
tL++;
fscanf(client, "%d %f %d", &id, &cag, &sus, &adm);
fscanf(client, "%d %d %f %d %d", &id, &passwd, &cag, &sus, &adm);
}
fclose(client);
return tL;
}
void sauvegardeDonnees(int tLogArticle, int tLogClient, int reference[], float weight[], float volume[], float unitPrice[], int clientID[], float cagnotte[], int suspended[], int isAdmin[])
void sauvegardeDonnees(int tLogArticle, int tLogClient, int reference[], float weight[], float volume[], float unitPrice[], int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[])
{
/*
Sauvegarde des données des articles et clients de tableaux vers des fichiers
@ -144,7 +145,7 @@ void sauvegardeDonnees(int tLogArticle, int tLogClient, int reference[], float w
+param suspended: tableau de l'état du compte des clients
*/
sauvegardeArticles(reference, weight, volume, unitPrice, tLogArticle);
sauvegardeClients(clientID, cagnotte, suspended, isAdmin, tLogClient);
sauvegardeClients(clientID, clientPassword, cagnotte, suspended, isAdmin, tLogClient);
}
void sauvegardeArticles(int reference[], float weight[], float volume[], float unitPrice[], int tLogArticle)
@ -178,7 +179,7 @@ void sauvegardeArticles(int reference[], float weight[], float volume[], float u
fclose(article);
}
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)
{
/*
Sauvegarde des données des articles de tableaux vers le fichier des articles
@ -202,7 +203,7 @@ void sauvegardeClients(int clientID[], float cagnotte[], int suspended[], int is
int i;
for(i=0; i<tLogClient; i++)
{
fprintf(client, "%d %f %d %d\n", clientID[i], cagnotte[i], suspended[i], isAdmin[i]);
fprintf(client, "%d %d %f %d %d\n", clientID[i], clientPassword[i], cagnotte[i], suspended[i], isAdmin[i]);
}
fclose(client);

Loading…
Cancel
Save