Browse Source

refactoring: improved code readability by removing redundant lines, renaming variables and adding comments for documentation.

remotes/origin/feature/employees-infos-access
fdai7207 2 years ago
parent
commit
c06136470d
  1. 29
      src/createEmployeeAccount.c

29
src/createEmployeeAccount.c

@ -5,7 +5,7 @@
bool isValidEmployeeID(const char* employeeId, int maximumStringLength)
{
int employeeIdLength = strlen(employeeId);
/* looping through the employeeId string until a space is found to return false or true otherwise*/
for(int i=0;i<employeeIdLength;i++)
{
if(employeeId[i]==' ')
@ -61,16 +61,9 @@ int StringLengthCounter(char* string)
return characterCounter;
}
bool verifyPassword(char* enteredPassword,char* passwordConfirmation)
{
if(strcmp(enteredPassword,passwordConfirmation)==0)
{
return true;
}
else
bool verifyPassword(char* enteredPassword,char* Confirmation)
{
return false;
}
return !(strcmp(enteredPassword,Confirmation));
}
@ -97,18 +90,18 @@ bool createNewEmployee(char* employeeId, char* employeePassword)
void getNewEmployeeCredentials()
{
const int Length = 21;
char employeeId[Length];
const int minimumPasswordLength = 5;
char employeePassword[Length];
char passwordVerfication[Length];
const int maxLength = 21;
char employeeId[maxLength];
const int minPasswordLength = 5;
char employeePassword[maxLength];
char passwordVerfication[maxLength];
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*/
scanf(" %[^\n]s",employeeId);
employeeId[Length] = '\0';
employeeId[maxLength] = '\0';
printf("\nplease enter your wished Password :\n");
@ -125,12 +118,12 @@ void getNewEmployeeCredentials()
if(verifyPassword(passwordVerfication,employeePassword))
{
if(isValidEmployeeID(employeeId,Length) && isValidPassword(employeePassword,minimumPasswordLength))
if(isValidEmployeeID(employeeId,maxLength) && isValidPassword(employeePassword,minPasswordLength))
{
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");
}
else if(isValidEmployeeID(employeeId,Length) && !isValidPassword(employeePassword,minimumPasswordLength))
else if(isValidEmployeeID(employeeId,maxLength) && !isValidPassword(employeePassword,minPasswordLength))
{
printf("Error : the entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol!");
}

Loading…
Cancel
Save