|
@ -2,7 +2,7 @@ |
|
|
|
|
|
|
|
|
#include "createEmployeeAccount.h" |
|
|
#include "createEmployeeAccount.h" |
|
|
|
|
|
|
|
|
bool isValidEmployeeID(const char* employeeId, int maximumStringLength) |
|
|
|
|
|
|
|
|
bool isValidEmployeeID(const char* employeeId,const int maximumStringLength) |
|
|
{ |
|
|
{ |
|
|
int employeeIdLength = strlen(employeeId); |
|
|
int employeeIdLength = strlen(employeeId); |
|
|
/* looping through the employeeId string until a space is found to return false or true otherwise*/ |
|
|
/* looping through the employeeId string until a space is found to return false or true otherwise*/ |
|
@ -17,7 +17,7 @@ bool isValidEmployeeID(const char* employeeId, int maximumStringLength) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isValidPassword( char *password, int minimumLength) |
|
|
|
|
|
|
|
|
bool isValidPassword( char *password,const int minimumLength) |
|
|
{ |
|
|
{ |
|
|
/*created a pointer(*stringpointer) which helps loop through characters of the string password*/ |
|
|
/*created a pointer(*stringpointer) which helps loop through characters of the string password*/ |
|
|
char *stringpointer = password; |
|
|
char *stringpointer = password; |
|
@ -48,20 +48,21 @@ bool isValidPassword( char *password, int minimumLength) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool isValidName(char* name, int minimalLength) |
|
|
|
|
|
|
|
|
bool isValidName(char* name,const int minimalLength) |
|
|
{ |
|
|
{ |
|
|
if(strlen(name) < minimalLength) |
|
|
|
|
|
|
|
|
int nameLength = strlen(name); |
|
|
|
|
|
if(nameLength < minimalLength) |
|
|
{ |
|
|
{ |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for(int i = 0;i<strlen(name);i++) |
|
|
|
|
|
|
|
|
for(int i = 0;i<nameLength;i++) |
|
|
{ |
|
|
{ |
|
|
if(isdigit(name[i])||ispunct(name[i])||isspace(name[i])) |
|
|
|
|
|
|
|
|
int currentCharacter = name[i]; |
|
|
|
|
|
if(isdigit(currentCharacter)||ispunct(currentCharacter)||isspace(currentCharacter)) |
|
|
{ |
|
|
{ |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
@ -120,8 +121,6 @@ bool createNewEmployee(char* employeeId, char* employeePassword) |
|
|
fprintf(employeesFile,"\n%s %s\n",employeeId,employeePassword); |
|
|
fprintf(employeesFile,"\n%s %s\n",employeeId,employeePassword); |
|
|
fclose(employeesFile); |
|
|
fclose(employeesFile); |
|
|
|
|
|
|
|
|
/*used the checkEmployeeCredentials to check if the new id and password are created successfully*/ |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -129,10 +128,7 @@ bool createNewEmployee(char* employeeId, char* employeePassword) |
|
|
void getNewEmployeeCredentials() |
|
|
void getNewEmployeeCredentials() |
|
|
{ |
|
|
{ |
|
|
employeedata *data = (employeedata*)malloc(sizeof(employeedata)); |
|
|
employeedata *data = (employeedata*)malloc(sizeof(employeedata)); |
|
|
const int maxLength = 21; |
|
|
|
|
|
char employeeId[maxLength]; |
|
|
char employeeId[maxLength]; |
|
|
const int minPasswordLength = 5; |
|
|
|
|
|
const int minimumNameLength = 4; |
|
|
|
|
|
char employeePassword[maxLength]; |
|
|
char employeePassword[maxLength]; |
|
|
char passwordVerfication[maxLength]; |
|
|
char passwordVerfication[maxLength]; |
|
|
|
|
|
|
|
@ -149,7 +145,6 @@ void getNewEmployeeCredentials() |
|
|
scanf(" %[^\n]s",passwordVerfication); |
|
|
scanf(" %[^\n]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\nplease enter your first name\n"); |
|
|
printf("\n\nplease enter your first name\n"); |
|
|