diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index b298929..db149f8 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -88,6 +88,7 @@ bool storeEmployeeData(const char *name,const char *lastName,const char *adress, if(employeesDatalist == NULL) { printf("Error : could not find file"); + fclose(employeesDatalist); return false; } else @@ -112,6 +113,7 @@ bool createNewEmployee(char* employeeId, char* employeePassword) if(employeesFile == NULL) { printf("Error: could not find the list of Employees"); + fclose(employeesFile); return false; } @@ -120,7 +122,7 @@ bool createNewEmployee(char* employeeId, char* employeePassword) /*used the checkEmployeeCredentials to check if the new id and password are created successfully*/ - return checkEmployeeCredentials(employeeId, employeePassword); + return true; } @@ -140,33 +142,39 @@ void getNewEmployeeCredentials() employeeId[maxLength] = '\0'; printf("\nplease enter your wished Password :\n"); - scanf("%s",employeePassword); + scanf(" %[^\n]s",employeePassword); employeePassword[strlen(employeePassword)] = '\0'; printf("\nplease confirm your Password :\n"); - scanf("%s",passwordVerfication); + scanf(" %[^\n]s",passwordVerfication); passwordVerfication[strlen(employeePassword)] = '\0'; if(verifyPassword(passwordVerfication,employeePassword) && isValidPassword(employeePassword,minPasswordLength) && isValidEmployeeID(employeeId,maxLength)) { printf("\n\nplease enter your first name\n"); - scanf("%s",data->firstName); + scanf(" %[^\n]s",data->firstName); printf("\n\nplease enter your last name\n"); - scanf("%s",data->lastName); + scanf(" %[^\n]s",data->lastName); - printf("\n\nplease enter your adress\n"); - scanf("%s",data->address); - - printf("\n\nplease enter your Phone number\n"); - scanf("%s",data->phoneNumber); + if(isValidName(data->firstName,minimumNameLength) && isValidName(data->lastName,minimumNameLength)) + { + printf("\n\nplease enter your adress\n"); + scanf(" %[^\n]s",data->address); - 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"); + printf("\n\nplease enter your Phone number\n"); + scanf(" %[^\n]s",data->phoneNumber); - storeEmployeeData(data->firstName,data->lastName,data->address,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"); + storeEmployeeData(data->firstName,data->lastName,data->address,data->phoneNumber); + } + else + { + printf("the given name contains unwanted characters(spaces, symbols,numbers)"); + } } else