From cd4fb8fb7dd896a8d8d6e28a9e79cafafd390b58 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Mon, 6 Feb 2023 06:49:08 +0100 Subject: [PATCH] implement the verifyPassword() function in the getNewEmployeeCredentials() so that the validity of the password can be checked twice. --- src/createEmployeeAccount.c | 42 +++++++++++++++++++++----------- src/employeesCredentialsList.txt | 5 ---- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 4af6f04..633561f 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -97,18 +97,18 @@ bool createNewEmployee(char* employeeId, char* employeePassword) void getNewEmployeeCredentials() { - const int employeeIdLength = 21; - char employeeId[employeeIdLength]; + const int Length = 21; + char employeeId[Length]; const int minimumPasswordLength = 5; - char employeePassword[minimumPasswordLength]; - + char employeePassword[Length]; + char passwordVerfication[Length]; 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[employeeIdLength] = '\0'; + employeeId[Length] = '\0'; printf("\nplease enter your wished Password :\n"); @@ -116,20 +116,34 @@ void getNewEmployeeCredentials() employeePassword[strlen(employeePassword)] = '\0'; - if(isValidEmployeeID(employeeId,employeeIdLength) && isValidPassword(employeePassword,minimumPasswordLength)) - { - 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("\nplease confirm your Password :\n"); + + scanf("%s",passwordVerfication); + + passwordVerfication[strlen(employeePassword)] = '\0'; - else if(isValidEmployeeID(employeeId,employeeIdLength) && !isValidPassword(employeePassword,minimumPasswordLength)) + if(verifyPassword(passwordVerfication,employeePassword)) { - printf("Error : the entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol!"); - } + + if(isValidEmployeeID(employeeId,Length) && isValidPassword(employeePassword,minimumPasswordLength)) + { + 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)) + { + 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 + { + printf("Error : the entered ID should contain a maximum of 20 letters"); + } + + } else { - printf("Error : the entered ID should contain a maximum of 20 letters"); + printf("the Verification password and the entered password dont match"); } - } diff --git a/src/employeesCredentialsList.txt b/src/employeesCredentialsList.txt index d44964d..ed5a12d 100644 --- a/src/employeesCredentialsList.txt +++ b/src/employeesCredentialsList.txt @@ -9,8 +9,3 @@ Julius Insertcatfdai7057 Mohamed MDfdai6618 Shivam Schivam007fdlt3781 - - - - -