@ -61,7 +61,9 @@ int StringLengthCounter(char* string)
return characterCounter ;
return characterCounter ;
}
}
bool storeEmployeeData ( char * name , char * lastName , char * adress , char * phoneNumber )
/*changed the string parameters to constants as an indicator that the function doesnt modify them*/
bool storeEmployeeData ( const char * name , const char * lastName , const char * adress , const char * phoneNumber )
{
{
FILE * employeesDatalist ;
FILE * employeesDatalist ;
employeesDatalist = fopen ( " src/employeesData.txt " , " a " ) ;
employeesDatalist = fopen ( " src/employeesData.txt " , " a " ) ;
@ -106,66 +108,54 @@ bool createNewEmployee(char* employeeId, char* employeePassword)
void getNewEmployeeCredentials ( )
void getNewEmployeeCredentials ( )
{
{
employeedata * data ;
data = ( employeedata * ) malloc ( sizeof ( employeedata ) ) ;
employeedata * data = ( employeedata * ) malloc ( sizeof ( employeedata ) ) ;
const int maxLength = 21 ;
const int maxLength = 21 ;
char employeeId [ maxLength ] ;
char employeeId [ maxLength ] ;
const int minPasswordLength = 5 ;
const int minPasswordLength = 5 ;
char employeePassword [ maxLength ] ;
char employeePassword [ maxLength ] ;
char passwordVerfication [ maxLength ] ;
char passwordVerfication [ maxLength ] ;
printf ( " please enter your wished Id : \n " ) ;
printf ( " please enter your wished Id : \n " ) ;
/*Added the regular expression [^\n] so that the string keep on getting read until a newline '\n' is found*/
/*Added the regular expression [^\n] so that the string keep on getting read until a newline '\n' is found*/
scanf ( " %[^ \n ]s " , employeeId ) ;
scanf ( " %[^ \n ]s " , employeeId ) ;
employeeId [ maxLength ] = ' \0 ' ;
employeeId [ maxLength ] = ' \0 ' ;
printf ( " \n please enter your wished Password : \n " ) ;
printf ( " \n please enter your wished Password : \n " ) ;
scanf ( " %s " , employeePassword ) ;
scanf ( " %s " , employeePassword ) ;
employeePassword [ strlen ( employeePassword ) ] = ' \0 ' ;
employeePassword [ strlen ( employeePassword ) ] = ' \0 ' ;
printf ( " \n please confirm your Password : \n " ) ;
printf ( " \n please confirm your Password : \n " ) ;
scanf ( " %s " , passwordVerfication ) ;
scanf ( " %s " , passwordVerfication ) ;
passwordVerfication [ strlen ( employeePassword ) ] = ' \0 ' ;
passwordVerfication [ strlen ( employeePassword ) ] = ' \0 ' ;
if ( verifyPassword ( passwordVerfication , employeePassword ) & & isValidPassword ( employeePassword , minPasswordLength ) & & isValidEmployeeID ( employeeId , maxLength ) )
if ( verifyPassword ( passwordVerfication , employeePassword ) & & isValidPassword ( employeePassword , minPasswordLength ) & & isValidEmployeeID ( employeeId , maxLength ) )
{
{
printf ( " \n \n please enter your first name \n " ) ;
printf ( " \n \n please enter your first name \n " ) ;
scanf ( " %s " , data - > firstName ) ;
scanf ( " %s " , data - > firstName ) ;
printf ( " \n \n please enter your last name \n " ) ;
printf ( " \n \n please enter your last name \n " ) ;
scanf ( " %s " , data - > lastName ) ;
scanf ( " %s " , data - > lastName ) ;
printf ( " \n \n please enter your adress \n " ) ;
printf ( " \n \n please enter your adress \n " ) ;
scanf ( " %s " , data - > adress ) ;
scanf ( " %s " , data - > address ) ;
printf ( " \n \n please enter your Phone number \n " ) ;
printf ( " \n \n please enter your Phone number \n " ) ;
scanf ( " %s " , data - > phoneNumber ) ;
scanf ( " %s " , data - > phoneNumber ) ;
createNewEmployee ( employeeId , employeePassword ) ? printf ( " \n \n Account created successfully ! \n \n " ) : printf ( " \n \n Could not create the Account please contact an employee of clearance 1 ! \n \n " ) ;
createNewEmployee ( employeeId , employeePassword ) ?
printf ( " \n \n Account created successfully ! \n \n " ) :
printf ( " \n \n Could not create the Account please contact an employee of clearance 1 ! \n \n " ) ;
storeEmployeeData ( data - > firstName , data - > lastName , data - > adress , data - > phoneNumber ) ;
storeEmployeeData ( data - > firstName , data - > lastName , data - > ad dress , data - > phoneNumber ) ;
}
}
else
else
{
{
printf ( " \n \n Error! one of these conditions is not met in your input \n \n " ) ;
printf ( " \n -t he entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol! \n " ) ;
printf ( " \n -the entered ID should contain a maximum of 20 letters! \n " ) ;
printf ( " \n -t he verification password should match with the entered password. \n " ) ;
printf ( " \n Error! one of these conditions is not met in your input. \n " ) ;
printf ( " \n -T he entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol. \n " ) ;
printf ( " \n -The entered ID should contain a maximum of 20 letters. \n " ) ;
printf ( " \n -T he verification password should match with the entered password. \n " ) ;
}
}
}
}