From fed4a0a3ad1f5496be75669d905135ade1b24b54 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sun, 5 Feb 2023 06:31:08 +0100 Subject: [PATCH] implement the isValidEmployeeID() in the getNewEmployeeCredentials to check Id's validity --- src/createEmployeeAccount.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 7abfb02..8532456 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -53,15 +53,32 @@ bool createNewEmployee(char* employeeId, char* employeePassword) void getNewEmployeeCredentials() { - char newEmployeeId[20]; - char newEmployeePassword[20]; + + int newEmployeeIdlength = 21; + char newEmployeeId[newEmployeeIdlength]; + char newEmployeePassword[newEmployeeIdlength]; + + printf("please enter your wished Id :\n"); + + scanf(" %[^\n]s",newEmployeeId); + + newEmployeeId[newEmployeeIdlength] = '\0'; + + printf("\nplease enter your wished Password :\n"); - printf("please enter your wished Id :"); - scanf("%s",newEmployeeId); - printf("please enter your wished Password :"); scanf("%s",newEmployeePassword); - createNewEmployee(newEmployeeId,newEmployeePassword) ? 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"); + newEmployeePassword[newEmployeeIdlength] = '\0'; + + if(isValidEmployeeID(newEmployeeId,newEmployeeIdlength)) + { + createNewEmployee(newEmployeeId,newEmployeePassword) ? 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 + { + printf("Error : the entered ID either contains space or exceeds the maximum of 20 characters!"); + } }