diff --git a/src/.employeeLogin.c.swp b/src/.employeeLogin.c.swp new file mode 100644 index 0000000..a2975fc Binary files /dev/null and b/src/.employeeLogin.c.swp differ diff --git a/src/employeeLogin.c b/src/employeeLogin.c index 624d0ae..0d44ddf 100644 --- a/src/employeeLogin.c +++ b/src/employeeLogin.c @@ -4,8 +4,8 @@ extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword) { - char listUsername[credentialLength]; - char listPassword[credentialLength]; + char* listUsername = malloc(credentialLength * sizeof(char*)); + char* listPassword = malloc(credentialLength * sizeof(char*)); FILE* employeeList = fopen("src/employeeList.txt","r"); @@ -15,15 +15,18 @@ extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword) exit(1); } else - { + { + /*loop that checks if the two strings seperated by space exist in the employee list*/ + while (fscanf(employeeList, "%s %s", listUsername, listPassword) != EOF) { - if (strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) == 0) + + if (!(strcmp(inputUsername, listUsername)) && !(strcmp(inputPassword, listPassword))) { fclose(employeeList); return 1; } - else if(strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) != 0) + else if(!(strcmp(inputUsername, listUsername)) && strcmp(inputPassword, listPassword)) { fclose(employeeList); return 2; @@ -32,46 +35,56 @@ extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword) fclose(employeeList); return 0; } + + free(inputUsername); + free(inputPassword); } -void employeeCredentials(char* username,char* password) +void employeeCredentials(char* inputUsername,char* inputPassword) { printf("Enter username: "); - scanf("%s", username); + scanf("%s", inputUsername); printf("Enter password: "); - scanf("%s", password); + scanf("%s", inputPassword); } void loginAsEmployee() { - int counter=2; - char username[credentialLength]; - char password[credentialLength]; - - employeeCredentials(username, password); + int counter=3; + char* username = malloc(credentialLength * sizeof(char*)); + char* password = malloc(credentialLength * sizeof(char*)); while(counter>0) { - if(checkEmployeeCredentials(username, password) == 0) + employeeCredentials(username, password); + + int checkCredentials = checkEmployeeCredentials(username,password); + + + if(checkCredentials == 0) { - printf("User not found\n"); - employeeCredentials(username, password); + printf("\n\nUser not found\n\n"); } - else if(checkEmployeeCredentials(username, password)==2) + else if(checkCredentials == 2) { - printf("Wrong Informations !\nyou have %d tries left\n",counter); - employeeCredentials(username, password); + printf("\n\nWrong Informations !\nyou have %d tries left\n\n",counter-1); --counter; } else { - printf("User Approved\n"); + printf("\n\nUser Approved\n\n"); break; } } + if(counter==0) { - printf("you used up all of the tries! account locked\n"); + + printf("you used up all of the tries! account locked\nPlease contact an employee of higher clearance !\n\n"); + } + free(username); + free(password); + }