Browse Source

refactoring: changed some variables and some functions names for a better readability and optimized the employeesAccess() function

remotes/origin/feature/the-main-menu
fdai7207 2 years ago
parent
commit
098ce77c87
  1. 32
      src/employeeLogin.c
  2. 2
      src/employeeLogin.h
  3. 2
      src/mainMenu.c

32
src/employeeLogin.c

@ -4,19 +4,11 @@
bool employeesAccess(char* employeesAccessCode) bool employeesAccess(char* employeesAccessCode)
{ {
if(strcmp(employeesAccessCode,employeeAccessKey) == 0)
{
return true;
}
return !(strcmp(employeesAccessCode,employeeAccessKey));
else
{
return false;
} }
}
extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword)
int checkEmployeeCredentials(char *inputUsername, char *inputPassword)
{ {
char* listUsername = malloc(credentialLength * sizeof(char*)); char* listUsername = malloc(credentialLength * sizeof(char*));
@ -55,21 +47,19 @@ extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword)
free(inputPassword); free(inputPassword);
} }
void inputEmployeeAccessCode()
void getEmployeeAccessCode()
{ {
char accessKey[10];
char accessCode[10];
int remainingAttempts = 10; int remainingAttempts = 10;
printf("\n\nPlease enter the Access key : "); 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");
@ -77,22 +67,22 @@ void inputEmployeeAccessCode()
break; break;
} }
else else
{ {
--remainingAttempts;
printf("\n\nAccess key didnt match! try again !\n\n"); printf("\n\nAccess key didnt match! try again !\n\n");
--remainingAttempts;
} }
if(remainingAttempts == 0) 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"); 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: "); printf("Enter username: ");
scanf("%s", inputUsername); scanf("%s", inputUsername);
@ -108,7 +98,7 @@ void loginAsEmployee()
while(counter>0) while(counter>0)
{ {
employeeCredentials(username, password);
getEmployeeCredentials(username, password);
int checkCredentials = checkEmployeeCredentials(username,password); int checkCredentials = checkEmployeeCredentials(username,password);

2
src/employeeLogin.h

@ -10,7 +10,7 @@ bool employeesAccess(char* employeesAccessCode);
int checkEmployeeCredentials(char* username , char* password); int checkEmployeeCredentials(char* username , char* password);
void employeeCredentials(char* username, char* password);
void getEmployeeCredentials(char* username, char* password);
void loginAsEmployee(); void loginAsEmployee();
#endif #endif

2
src/mainMenu.c

@ -107,7 +107,7 @@ void menuInput()
case 2 : printf("\ncreateCostumerAccount() function will be implemented here soon\n\n"); case 2 : printf("\ncreateCostumerAccount() function will be implemented here soon\n\n");
break; break;
case 3 : inputEmployeeAccessCode();
case 3 : getEmployeeAccessCode();
break; break;
case 4 : printf("\e[1;1H\e[2J"); case 4 : printf("\e[1;1H\e[2J");

Loading…
Cancel
Save