From 0ec4eadc9753a8ddde1ea8c855a9ad26dc2e6bbb Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sun, 5 Feb 2023 21:09:21 +0100 Subject: [PATCH] refactoring: made code more readable by changing some variable name in the isValidPassword() function and added some documentation. --- src/createEmployeeAccount.c | 15 +++++++-------- src/createEmployeeAccount.h | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 37b8452..f2dcd1a 100644 --- a/src/createEmployeeAccount.c +++ b/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 diff --git a/src/createEmployeeAccount.h b/src/createEmployeeAccount.h index 7940693..12b38f2 100644 --- a/src/createEmployeeAccount.h +++ b/src/createEmployeeAccount.h @@ -8,7 +8,7 @@ #include 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);