From 098ce77c87a6837bf17269fcecde5ab31a1b4606 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Thu, 2 Feb 2023 01:34:36 +0100 Subject: [PATCH] refactoring: changed some variables and some functions names for a better readability and optimized the employeesAccess() function --- src/employeeLogin.c | 38 ++++++++++++++------------------------ src/employeeLogin.h | 2 +- src/mainMenu.c | 2 +- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/employeeLogin.c b/src/employeeLogin.c index 6ec85db..3182746 100644 --- a/src/employeeLogin.c +++ b/src/employeeLogin.c @@ -4,19 +4,11 @@ bool employeesAccess(char* employeesAccessCode) { - if(strcmp(employeesAccessCode,employeeAccessKey) == 0) - { - return true; - } - - else - { - return false; - } + return !(strcmp(employeesAccessCode,employeeAccessKey)); } -extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword) +int checkEmployeeCredentials(char *inputUsername, char *inputPassword) { char* listUsername = malloc(credentialLength * sizeof(char*)); @@ -55,44 +47,42 @@ extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword) free(inputPassword); } -void inputEmployeeAccessCode() +void getEmployeeAccessCode() { - char accessKey[10]; + char accessCode[10]; int remainingAttempts = 10; - printf("\n\nPlease enter the Access key : "); - // scanf("%s",accessKey); - while(remainingAttempts>0) + while(remainingAttempts > 0) { - scanf("%s",accessKey); + scanf("%s",accessCode); - if(employeesAccess(accessKey)==true) + if(employeesAccess(accessCode)) { - printf("\n\nAccess granted!\n\n"); + printf("\n\nAccess granted!\n\n"); loginAsEmployee(); - break; + break; } + else { - --remainingAttempts; printf("\n\nAccess key didnt match! try again !\n\n"); - + --remainingAttempts; } + 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) +void getEmployeeCredentials(char* inputUsername,char* inputPassword) { printf("Enter username: "); scanf("%s", inputUsername); @@ -108,7 +98,7 @@ void loginAsEmployee() while(counter>0) { - employeeCredentials(username, password); + getEmployeeCredentials(username, password); int checkCredentials = checkEmployeeCredentials(username,password); diff --git a/src/employeeLogin.h b/src/employeeLogin.h index c563e18..d6f3314 100644 --- a/src/employeeLogin.h +++ b/src/employeeLogin.h @@ -10,7 +10,7 @@ bool employeesAccess(char* employeesAccessCode); int checkEmployeeCredentials(char* username , char* password); -void employeeCredentials(char* username, char* password); +void getEmployeeCredentials(char* username, char* password); void loginAsEmployee(); #endif diff --git a/src/mainMenu.c b/src/mainMenu.c index 40c553f..b2d8243 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 : inputEmployeeAccessCode(); + case 3 : getEmployeeAccessCode(); break; case 4 : printf("\e[1;1H\e[2J");