Browse Source

refactoring: made code more readable by changing some variable name in the isValidPassword() function and added some documentation.

remotes/origin/feature/employees-infos-access
fdai7207 2 years ago
parent
commit
0ec4eadc97
  1. 15
      src/createEmployeeAccount.c
  2. 2
      src/createEmployeeAccount.h

15
src/createEmployeeAccount.c

@ -16,11 +16,11 @@ int StringLengthCounter(char* string)
return characterCounter;
}
bool isValidPassword(char* employeePassword, int minimumStringLength)
bool isValidPassword( char *password, int minimumLength)
{
char* stringpointer = employeePassword;
int employeePasswordLength = 0;
bool letterFound = false, punctuationFound = false, numberFound = false;
/*created a pointer(*stringpointer) which helps loop through characters of the string password*/
char *stringpointer = password;
bool letterFound = false, symbolFound = false, numberFound = false;
while(*stringpointer!='\0')
{
@ -34,14 +34,13 @@ bool isValidPassword(char* employeePassword, int minimumStringLength)
}
else if(ispunct(* stringpointer))
{
punctuationFound = true;
symbolFound = true;
}
if( employeePasswordLength >= minimumStringLength && letterFound && numberFound && punctuationFound)
if( strlen(password) >= minimumLength && letterFound && numberFound && symbolFound)
{
return true;
}
++stringpointer;
++employeePasswordLength;
}
return false;
@ -112,7 +111,7 @@ void getNewEmployeeCredentials()
else if(isValidEmployeeID(employeeId,employeeIdLength) && !isValidPassword(employeePassword,minimumPasswordLength))
{
printf("Error : the entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 punctuation character!");
printf("Error : the entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol!");
}
else

2
src/createEmployeeAccount.h

@ -8,7 +8,7 @@
#include<ctype.h>
bool isValidEmployeeID(const char* employee, int maximumLength);
bool isValidPassword(char* employeePassword, int minimumStringLength);
bool isValidPassword( char* password, int minimumLength);
bool createNewEmployee(char* employeeId, char* employeePassword);
int StringLengthCounter(char* string);

Loading…
Cancel
Save