Browse Source
implement the functions employeeCredentials() and loginAsEmployee() for employees to access their accounts.
remotes/origin/feature/the-main-menu
implement the functions employeeCredentials() and loginAsEmployee() for employees to access their accounts.
remotes/origin/feature/the-main-menu
fdai7207
2 years ago
8 changed files with 93 additions and 30 deletions
-
6build-project.sh
-
1project.yml
-
89src/employeeLogin.c
-
15src/employeeLogin.h
-
BINsrc/main
-
3src/main.c
-
5src/mainMenu.c
-
2src/mainMenu.h
@ -1,6 +1,12 @@ |
|||
clear |
|||
ceedling test:all |
|||
cd src/ |
|||
cp employeeLogin.c employeeLogin.c.bak |
|||
sed -i 's/src\///g' employeeLogin.c |
|||
gcc main.c mainMenu.c -o main |
|||
./main |
|||
rm main |
|||
cp employeeLogin.c.bak employeeLogin.c |
|||
rm employeeLogin.c.bak |
|||
cd .. |
|||
rm -r build/ |
@ -1,22 +1,77 @@ |
|||
#include "mainMenu.h" |
|||
#include "employeeLogin.h" |
|||
|
|||
int checkEmployeeCredentials(char *inputUsername, char *inputPassword) |
|||
extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword) |
|||
{ |
|||
|
|||
char listUsername[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) { |
|||
fclose(employeeList); |
|||
return 1; |
|||
} |
|||
else if(strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) != 0){ |
|||
fclose(employeeList); |
|||
return 2; |
|||
} |
|||
} |
|||
fclose(employeeList); |
|||
return 0; |
|||
char listUsername[credentialLength]; |
|||
char listPassword[credentialLength]; |
|||
|
|||
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); |
|||
return 1; |
|||
} |
|||
else if(strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) != 0) |
|||
{ |
|||
fclose(employeeList); |
|||
return 2; |
|||
} |
|||
} |
|||
fclose(employeeList); |
|||
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"); |
|||
} |
|||
|
|||
} |
@ -1,16 +1,13 @@ |
|||
#ifndef EMPLOYEELOGIN_H_ |
|||
#define EMPLOYEELOGIN_H_ |
|||
#ifndef LOGINEMPLOYEE_H_ |
|||
#define LOGINEMPLOYEE_H_ |
|||
|
|||
#include<stdio.h> |
|||
#include<stdlib.h> |
|||
#include<stdbool.h> |
|||
#include<string.h> |
|||
|
|||
#define credentialLength 20 |
|||
|
|||
|
|||
|
|||
int checkEmployeeCredentials(char* inputUsername , char* inputPassword); |
|||
int checkEmployeeCredentials(char* username , char* password); |
|||
void employeeCredentials(char* username, char* password); |
|||
void loginAsEmployee(); |
|||
|
|||
#endif |
|||
|
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue