diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index ab4f38a..3951a63 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -16,6 +16,38 @@ int StringLengthCounter(char* string) return characterCounter; } +bool isValidPassword(char* employeePassword, int minimumStringLength) +{ + char* stringpointer = employeePassword; + int employeePasswordLength = 0; + bool letterFound = false, punctuationFound = false, numberFound = false; + + while(*stringpointer!='\0') + { + if(isalpha(* stringpointer)) + { + letterFound = true; + } + else if(isdigit(* stringpointer)) + { + numberFound = true; + } + else if(ispunct(* stringpointer)) + { + punctuationFound = true; + } + if( employeePasswordLength >= minimumStringLength && letterFound && numberFound && punctuationFound) + { + return true; + } + ++stringpointer; + ++employeePasswordLength; + } + + return false; + +} + bool isValidEmployeeID(const char* employeeId, int maximumStringLength) { @@ -54,9 +86,10 @@ bool createNewEmployee(char* employeeId, char* employeePassword) void getNewEmployeeCredentials() { - const int employeeIdlength = 21; - char employeeId[employeeIdlength]; - char employeePassword[employeeIdlength]; + const int employeeIdLength = 21; + char employeeId[employeeIdLength]; + const int minimumPasswordLength = 5; + char employeePassword[minimumPasswordLength]; printf("please enter your wished Id :\n"); @@ -64,15 +97,15 @@ void getNewEmployeeCredentials() scanf(" %[^\n]s",employeeId); - employeeId[employeeIdlength] = '\0'; + employeeId[employeeIdLength] = '\0'; printf("\nplease enter your wished Password :\n"); scanf("%s",employeePassword); - employeePassword[employeeIdlength] = '\0'; + employeePassword[strlen(employeePassword)] = '\0'; - if(isValidEmployeeID(employeeId,employeeIdlength)) + if(isValidEmployeeID(employeeId,employeeIdLength)) { 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"); } diff --git a/src/createEmployeeAccount.h b/src/createEmployeeAccount.h index 22cf4d7..7940693 100644 --- a/src/createEmployeeAccount.h +++ b/src/createEmployeeAccount.h @@ -5,8 +5,10 @@ #include #include #include +#include bool isValidEmployeeID(const char* employee, int maximumLength); +bool isValidPassword(char* employeePassword, int minimumStringLength); bool createNewEmployee(char* employeeId, char* employeePassword); int StringLengthCounter(char* string); diff --git a/src/employeeList.txt b/src/employeeList.txt index 94986be..ed5a12d 100644 --- a/src/employeeList.txt +++ b/src/employeeList.txt @@ -9,4 +9,3 @@ Julius Insertcatfdai7057 Mohamed MDfdai6618 Shivam Schivam007fdlt3781 - diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index 5ba39aa..7cfdb5d 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -49,6 +49,54 @@ void test_isNotValidEmployeeID(void) } +void test_validEmployeePassword(void) +{ + /*Arrange*/ + + char* validPassword [] = {"Atharva.123","02.September.2023","fdai7207.","array[20]","malloc(20*sizeof(int))","12.2E1234"}; + int minimalLength = 8; + bool validPasswordResult[6]; + + /*Act*/ + + for(int i=0; i<6; i++) + { + validPasswordResult[i] = isValidPassword(validPassword[i],minimalLength); + } + + /*Assert*/ + + for(int i=0; i<6; i++) + { + TEST_ASSERT_TRUE(validPasswordResult[i]); + } + +} + +void test_invalidEmployeePassword(void) +{ + /*Arrange*/ + + char* invalidPassword [] = {"fizzbuzzio","02.09.2023",".^^_*+/-.","RTX4050ti","Can","github.com/bankmanagement-system"}; + int minimalLength = 8; + bool invalidPasswordResult[6]; + + /*Act*/ + + for(int i=0; i<6; i++) + { + invalidPasswordResult[i] = isValidPassword(invalidPassword[i],minimalLength); + } + + /*Assert*/ + + for(int i=0; i<6; i++) + { + TEST_ASSERT_FALSE(invalidPasswordResult[i]); + } + +} + void test_employeeCreatedSuccessfully(void) { /*Arrange*/