From 557709bdd6fbdbabc91846daa6f83d86a675180a Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Thu, 2 Feb 2023 00:53:37 +0100 Subject: [PATCH] implement the function inputEmployeeAccessCode() so that only employees can access the loginAsEmployee() function. --- build-project.sh | 1 + src/employeeLogin.c | 39 ++++++++++++++++++++++++++++++++++++++- src/employeeLogin.h | 2 +- src/mainMenu.c | 2 +- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/build-project.sh b/build-project.sh index 5988d59..3aac8dc 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,3 +1,4 @@ +trap 'echo "Interrupted"; rm main; cp employeeLogin.c.bak employeeLogin.c; rm employeeLogin.c.bak; cd ..; rm -r build/; exit' SIGINT clear ceedling test:all cd src/ diff --git a/src/employeeLogin.c b/src/employeeLogin.c index dfcac61..6ec85db 100644 --- a/src/employeeLogin.c +++ b/src/employeeLogin.c @@ -4,7 +4,7 @@ bool employeesAccess(char* employeesAccessCode) { - if(strcmp(employeesAccessCode,accessKey) == 0) + if(strcmp(employeesAccessCode,employeeAccessKey) == 0) { return true; } @@ -55,6 +55,43 @@ extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword) free(inputPassword); } +void inputEmployeeAccessCode() +{ + char accessKey[10]; + + int remainingAttempts = 10; + + + printf("\n\nPlease enter the Access key : "); + // scanf("%s",accessKey); + + while(remainingAttempts>0) + { + scanf("%s",accessKey); + + if(employeesAccess(accessKey)==true) + { + printf("\n\nAccess granted!\n\n"); + + loginAsEmployee(); + break; + + } + else + { + --remainingAttempts; + printf("\n\nAccess key didnt match! try again !\n\n"); + + } + if(remainingAttempts == 0) + { + printf("you've reached the maximum number of tries!\nplease contact an employee of a high clearance(2 or higher) \n\n"); + } + } + + +} + void employeeCredentials(char* inputUsername,char* inputPassword) { printf("Enter username: "); diff --git a/src/employeeLogin.h b/src/employeeLogin.h index dd77acc..c563e18 100644 --- a/src/employeeLogin.h +++ b/src/employeeLogin.h @@ -1,7 +1,7 @@ #ifndef LOGINEMPLOYEE_H_ #define LOGINEMPLOYEE_H_ -#define accessKey "DF9E9A8B5E" +#define employeeAccessKey "DF9E9A8B5E" #define credentialLength 20 #include diff --git a/src/mainMenu.c b/src/mainMenu.c index f9f48a2..40c553f 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -107,7 +107,7 @@ void menuInput() case 2 : printf("\ncreateCostumerAccount() function will be implemented here soon\n\n"); break; - case 3 : loginAsEmployee(); + case 3 : inputEmployeeAccessCode(); break; case 4 : printf("\e[1;1H\e[2J");