@ -4,8 +4,8 @@
extern int checkEmployeeCredentials ( char * inputUsername , char * inputPassword )
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 " ) ;
FILE * employeeList = fopen ( " src/employeeList.txt " , " r " ) ;
@ -16,14 +16,17 @@ extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword)
}
}
else
else
{
{
/*loop that checks if the two strings seperated by space exist in the employee list*/
while ( fscanf ( employeeList , " %s %s " , listUsername , listPassword ) ! = EOF )
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 ) ;
fclose ( employeeList ) ;
return 1 ;
return 1 ;
}
}
else if ( strcmp ( inputUsername , listUsername ) = = 0 & & strcmp ( inputPassword , listPassword ) ! = 0 )
else if ( ! ( strcmp ( inputUsername , listUsername ) ) & & strcmp ( inputPassword , listPassword ) )
{
{
fclose ( employeeList ) ;
fclose ( employeeList ) ;
return 2 ;
return 2 ;
@ -32,46 +35,56 @@ extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword)
fclose ( employeeList ) ;
fclose ( employeeList ) ;
return 0 ;
return 0 ;
}
}
free ( inputUsername ) ;
free ( inputPassword ) ;
}
}
void employeeCredentials ( char * username , char * password )
void employeeCredentials ( char * inp utU sername, char * in putP assword)
{
{
printf ( " Enter username: " ) ;
printf ( " Enter username: " ) ;
scanf ( " %s " , username ) ;
scanf ( " %s " , inp utU sername) ;
printf ( " Enter password: " ) ;
printf ( " Enter password: " ) ;
scanf ( " %s " , password ) ;
scanf ( " %s " , in putP assword) ;
}
}
void loginAsEmployee ( )
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 )
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 \n User not found \n \n " ) ;
}
}
else if ( checkEmployeeCredentials ( username , password ) = = 2 )
else if ( checkCredentials = = 2 )
{
{
printf ( " Wrong Informations ! \n you have %d tries left \n " , counter ) ;
employeeCredentials ( username , password ) ;
printf ( " \n \n Wrong Informations ! \n you have %d tries left \n \n " , counter - 1 ) ;
- - counter ;
- - counter ;
}
}
else
else
{
{
printf ( " User Approved \n " ) ;
printf ( " \n \n User Approved \n \n " ) ;
break ;
break ;
}
}
}
}
if ( counter = = 0 )
if ( counter = = 0 )
{
{
printf ( " you used up all of the tries! account locked \n " ) ;
printf ( " you used up all of the tries! account locked \n Please contact an employee of higher clearance ! \n \n " ) ;
}
}
free ( username ) ;
free ( password ) ;
}
}