|
@ -1,22 +1,77 @@ |
|
|
|
|
|
#include "mainMenu.h" |
|
|
#include "employeeLogin.h" |
|
|
#include "employeeLogin.h" |
|
|
|
|
|
|
|
|
int checkEmployeeCredentials(char *inputUsername, char *inputPassword) |
|
|
|
|
|
|
|
|
extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
char listUsername[credentialLength]; |
|
|
char listUsername[credentialLength]; |
|
|
char listPassword[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) { |
|
|
|
|
|
|
|
|
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); |
|
|
fclose(employeeList); |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
else if(strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) != 0){ |
|
|
|
|
|
|
|
|
else if(strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) != 0) |
|
|
|
|
|
{ |
|
|
fclose(employeeList); |
|
|
fclose(employeeList); |
|
|
return 2; |
|
|
return 2; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
fclose(employeeList); |
|
|
fclose(employeeList); |
|
|
return 0; |
|
|
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"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |