You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
#include "employeeLogin.c"
#include "createEmployeeAccount.h"
bool isValidEmployeeID(const char* employeeId, int maximumStringLength) { int employeeIdLength = strlen(employeeId);
for(int i=0;i<employeeIdLength;i++) { if(employeeId[i]==' ') { return false; } } return employeeIdLength <= maximumStringLength ; }
bool isValidPassword( char *password, int minimumLength) { /*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') { if(isalpha(* stringpointer)) { letterFound = true; } else if(isdigit(* stringpointer)) { numberFound = true; } else if(ispunct(* stringpointer)) { symbolFound = true; } if( strlen(password) >= minimumLength && letterFound && numberFound && symbolFound) { return true; } ++stringpointer; }
return false;
}
int StringLengthCounter(char* string) { int characterCounter = 0; int i = 0; while(string[i] !='\0') { characterCounter++; ++i; } string[characterCounter] = '\0'; return characterCounter; }
bool verifyPassword(char* enteredPassword,char* passwordConfirmation) { if(strcmp(enteredPassword,passwordConfirmation)==0) { return true; } else { return false; } }
bool createNewEmployee(char* employeeId, char* employeePassword) { FILE* employeesFile; employeesFile = fopen("src/employeesCredentialsList.txt","a");
if(employeesFile == NULL) { printf("Error: could not find the list of Employees"); return false; }
fprintf(employeesFile,"\n%s %s\n",employeeId,employeePassword); fclose(employeesFile);
/*used the checkEmployeeCredentials to check if the new id and password are created successfully*/
return checkEmployeeCredentials(employeeId, employeePassword); }
void getNewEmployeeCredentials() { const int Length = 21; char employeeId[Length]; const int minimumPasswordLength = 5; 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[Length] = '\0'; printf("\nplease enter your wished Password :\n");
scanf("%s",employeePassword);
employeePassword[strlen(employeePassword)] = '\0';
printf("\nplease confirm your Password :\n");
scanf("%s",passwordVerfication); passwordVerfication[strlen(employeePassword)] = '\0';
if(verifyPassword(passwordVerfication,employeePassword)) {
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("the Verification password and the entered password dont match"); } }
|