RandomString(SafeData[playerid][eSalt], ACCOUNT_MAX_SALT_SIZE); printf("1) salt = %s", SafeData[playerid][eSalt]); SHA256_PassHash(password, SafeData[playerid][eSalt], password_hash, sizeof(password_hash)); strmid(SafeData[playerid][ePassword], password_hash, 0, strlen(password_hash), ACCOUNT_MAX_PASSWORD_SIZE); printf("2) salt = %s", SafeData[playerid][eSalt]); strmid(SafeData[playerid][eEmail], email, 0, strlen(email), ACCOUNT_MAX_EMAIL_SIZE); printf("3) salt = %s", SafeData[playerid][eSalt]);
1) salt = H2422186RrsL1lUK8fj55TH01oIOSkfZ29WbBf589p440tXoz9M6DZz72n9M2k2597mq437m 2) salt = H2422186RrsL1lUK8fj55TH01oIOSkfZ29WbBf589p440tXoz9M6DZz72n9M2k2597mq437m 3) salt = H2422186RrsL1lUK8fj55TH01oIOSkfZ29WbBf589p440tXoz9M6DZz72n9M2k2597mq437mtestemail123@gmail.com
#define ACCOUNT_MAX_NAME_SIZE 24 #define ACCOUNT_MAX_PASSWORD_SIZE 72 #define ACCOUNT_MAX_SALT_SIZE 72 #define ACCOUNT_MAX_EMAIL_SIZE 72 #define ACCOUNT_MAX_IP_SIZE 16
enum eSafeData { eID, eName[ACCOUNT_MAX_NAME_SIZE], ePassword[ACCOUNT_MAX_PASSWORD_SIZE], eSalt[ACCOUNT_MAX_SALT_SIZE], eEmail[ACCOUNT_MAX_EMAIL_SIZE] }; new SafeData[MAX_PLAYERS][eSafeData];
new str[] = "Hello";
// same as
new str[] = { 'H', 'e', 'l', 'l', 'o', '\0' };
The problem is more likely that your salt is not terminated with a null terminator. When you print a string memory is read until the next null terminator is found. If there isn't a null terminator at the end of the string then it'll just continue reading into adjacent memory where other variables are stored. That's called buffer overflow.
Do you mind showing your RandomString method? |
stock RandomString(strDest[], strLen = 10) { while(strLen--) { strDest[strLen] = random(2) ? (random(26) + (random(2) ? 'a' : 'A')) : (random(10) + '0'); } }
If string is 72 characters long you need 73 characters. Why?
First of all know that strings in PAWN are no different than an array. Basically those are the same: pawn Код:
#e: Damn internet outage |
new password[ACCOUNT_MAX_PASSWORD_SIZE], password_hash[128], email[ACCOUNT_MAX_EMAIL_SIZE]; if(sscanf(params, "s["#ACCOUNT_MAX_PASSWORD_SIZE"]s["#ACCOUNT_MAX_EMAIL_SIZE"]", password, email)) { SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /register [pass] [email]"); return 1; }
RandomString(SafeData[playerid][eSalt], ACCOUNT_MAX_SALT_SIZE - 1);
Fixed it by doing this:
Код:
RandomString(SafeData[playerid][eSalt], ACCOUNT_MAX_SALT_SIZE - 1); |
stock RandomString(strDest[], strLen = 10)
{
strDest[strLen] = EOS;
while(strLen--)
{
strDest[strLen] = random(2) ? (random(26) + (random(2) ? 'a' : 'A')) : (random(10) + '0');
}
}
No... Like others told you, it needs EOS (End of String).
PHP код:
|