Browse Source

refactoring: rename variables for better understanding, write comment to explain function generateCheckString(), optimize intendation

remotes/origin/feature/customer-login
fdai7057 2 years ago
parent
commit
79573d2381
  1. 17
      src/StringManipulation.c

17
src/StringManipulation.c

@ -26,18 +26,19 @@ char *to_string(int number)
}
}
char *generateCheckString(int ID, char *password)
char *generateCheckString(int customerID, char *customerPassword)
{
char *IDString = to_string(ID);
/*The purpose of this function is to generate a string that is needed when a user wants to login.
* This string is searched for in the customer-data file and if it is found, the login is successful.
* This function is needed when a new user is created because then it is written in the file for the first time.
* The format of the string is: [ID]=[PASSWORD]*/
char *IDString = to_string(customerID);
int IDLength = strlen(IDString);
int passwordLength = strlen(password);
/*the checkString has this form: ID=password, so in order to calculate its length the length of the ID, one byte for the =, the length of the password and
* one byte for '\0' are needed.*/
int passwordLength = strlen(customerPassword);
int checkStringLength = IDLength + 1 + passwordLength + 1;
char *checkString = calloc(checkStringLength, sizeof(char));
checkString = strcat(IDString, "=");
checkString = strcat(checkString, password);
checkString = strcat(checkString, customerPassword);
*(checkString+checkStringLength) = '\0';
return checkString;:w
return checkString;
}
Loading…
Cancel
Save