From 9c0a02dfbb424c62150248a9ee22ccde992e66cb Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Wed, 1 Feb 2023 16:30:01 +0100 Subject: [PATCH] implement the functions employeeCredentials() and loginAsEmployee() for employees to access their accounts. --- build-project.sh | 6 +++ project.yml | 1 + src/employeeLogin.c | 89 +++++++++++++++++++++++++++++++++++--------- src/employeeLogin.h | 15 +++----- src/main | Bin 16408 -> 0 bytes src/main.c | 3 +- src/mainMenu.c | 7 ++-- src/mainMenu.h | 2 + 8 files changed, 93 insertions(+), 30 deletions(-) delete mode 100755 src/main diff --git a/build-project.sh b/build-project.sh index 420b964..5988d59 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,6 +1,12 @@ clear ceedling test:all cd src/ +cp employeeLogin.c employeeLogin.c.bak +sed -i 's/src\///g' employeeLogin.c gcc main.c mainMenu.c -o main ./main rm main +cp employeeLogin.c.bak employeeLogin.c +rm employeeLogin.c.bak +cd .. +rm -r build/ diff --git a/project.yml b/project.yml index e253248..51a5a2a 100644 --- a/project.yml +++ b/project.yml @@ -35,6 +35,7 @@ - -:test/support :source: - src/** + - src/ :support: - test/support :libraries: [] diff --git a/src/employeeLogin.c b/src/employeeLogin.c index 542526f..624d0ae 100644 --- a/src/employeeLogin.c +++ b/src/employeeLogin.c @@ -1,22 +1,77 @@ +#include "mainMenu.h" #include "employeeLogin.h" -int checkEmployeeCredentials(char *inputUsername, char *inputPassword) +extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword) { - char listUsername[credentialLength]; - char listPassword[credentialLength]; - - FILE *employeeList = fopen("src/employeeList.txt", "r"); - while (fscanf(employeeList, "%s %s", listUsername, listPassword) != EOF) { - if (strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) == 0) { - fclose(employeeList); - return 1; - } - else if(strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) != 0){ - fclose(employeeList); - return 2; - } - } - fclose(employeeList); - return 0; + char listUsername[credentialLength]; + char listPassword[credentialLength]; + + FILE* employeeList = fopen("src/employeeList.txt","r"); + + if(employeeList == NULL ) + { + printf("file does not exist"); + exit(1); + } + else + { + while (fscanf(employeeList, "%s %s", listUsername, listPassword) != EOF) + { + if (strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) == 0) + { + fclose(employeeList); + return 1; + } + else if(strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) != 0) + { + fclose(employeeList); + return 2; + } + } + fclose(employeeList); + return 0; + } +} + +void employeeCredentials(char* username,char* password) +{ + printf("Enter username: "); + scanf("%s", username); + printf("Enter password: "); + scanf("%s", password); +} + +void loginAsEmployee() +{ + int counter=2; + char username[credentialLength]; + char password[credentialLength]; + + employeeCredentials(username, password); + + while(counter>0) + { + if(checkEmployeeCredentials(username, password) == 0) + { + printf("User not found\n"); + employeeCredentials(username, password); + } + else if(checkEmployeeCredentials(username, password)==2) + { + printf("Wrong Informations !\nyou have %d tries left\n",counter); + employeeCredentials(username, password); + --counter; + } + else + { + printf("User Approved\n"); + break; + } + } + if(counter==0) + { + printf("you used up all of the tries! account locked\n"); + } + } diff --git a/src/employeeLogin.h b/src/employeeLogin.h index 6e4cb65..485955f 100644 --- a/src/employeeLogin.h +++ b/src/employeeLogin.h @@ -1,16 +1,13 @@ -#ifndef EMPLOYEELOGIN_H_ -#define EMPLOYEELOGIN_H_ +#ifndef LOGINEMPLOYEE_H_ +#define LOGINEMPLOYEE_H_ -#include -#include -#include -#include #define credentialLength 20 - - -int checkEmployeeCredentials(char* inputUsername , char* inputPassword); +int checkEmployeeCredentials(char* username , char* password); +void employeeCredentials(char* username, char* password); +void loginAsEmployee(); #endif + diff --git a/src/main b/src/main deleted file mode 100755 index fad988bb3623d9069264d63cdfeaecddd9fa83f8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16408 zcmeHOdvH|M89y5cga{-cAP<#`LI>((Ng{**0(lVFAOQ-fSi$Sf?%iZ%vp4SEg~So1 z1zR&TmO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1FOL6@us+|%nWuS$*PiD!Obu4l)Ng+a@b@rxH49vEQ=!gfr@ z!Pslh^YMk1N}uCoH*ClJL>Lps@$>w%R@?jasV#4rqTAQ%IT72>%^|A7_Fn2cMWx~n y?NF|O2XYmDH1+0q`2I`R2gi #include +#define credentialLength 20 + bool agePermission(int age); bool checkIfInteger(char* userInput); bool chooseOption(int choiceInput);