MySQL + Whirlpool (Saving/Loading issues) -
GXLZPGX - 03.09.2015
I'm having issue's relogging. I can register an account successfully of course, but if I quit the server and reconnect, when it asks for my password I can't seem to log in. I also have an admin control panel set up on my website that can't log in either, when all was well before. I don't remember what I changed, my mind is fried.
PHP код:
stock RegisterPlayer(playerid, regpass[])
{
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
new query[256];
new EncryptedPass[130];
WP_Hash(EncryptedPass, sizeof(EncryptedPass), regpass);
format(query, sizeof(query), "INSERT INTO user_accounts (Username, Password, PlayerPos, Skin) VALUES ('%s', '%s', '1.0 2.0 3.0', '0')", pName, EncryptedPass);
mysql_query(query);
LoginPlayer(playerid);
return 1;
}
stock LoginPlayer(playerid)
{
new query[126];
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(query, sizeof(query), "SELECT * FROM user_accounts WHERE Username = '%s'", pName);
mysql_query(query);
mysql_store_result();
while(mysql_fetch_row_format(query, "|"))
{
mysql_fetch_field_row(Player[playerid][Username], "Username");
mysql_fetch_field_row(Player[playerid][Password], "Password");
mysql_fetch_field_row(query, "PlayerPos"); sscanf(query, "fff", Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2]);
mysql_fetch_field_row(query, "AdminLevel"); Player[playerid][AdminLevel] = strval(query);
mysql_fetch_field_row(query, "Skin"); Player[playerid][Skin] = strval(query);
mysql_fetch_field_row(query, "LoggedIn"); Player[playerid][LoggedIn] = strval(query);
mysql_fetch_field_row(query, "Money"); Player[playerid][Money] = strval(query);
mysql_fetch_field_row(query, "ID"); Player[playerid][ID] = strval(query);
}
GivePlayerMoney(playerid, Player[playerid][Money]);
LogIn(pName);
}
stock SavePlayer(playerid)
{
new query[1024];
new EncryptedPass[130];
WP_Hash(EncryptedPass, sizeof(EncryptedPass), Player[playerid][Password]);
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
Player[playerid][Money] = GetPlayerMoney(playerid);
Player[playerid][Skin] = GetPlayerSkin(playerid);
GetPlayerPos(playerid, Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2]);
format(query, sizeof(query), "UPDATE user_accounts SET Username = '%s', Password = '%s', PlayerPos = '%f %f %f', AdminLevel = '%d', Skin = '%d', Money = '%d' WHERE Username = '%s'", pName, EncryptedPass, Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2], Player[playerid][AdminLevel], Player[playerid][Skin], Player[playerid][Money], pName);
mysql_query(query);
printf("Player ID %d (%s) has been updated", playerid, pName);
}
PHP код:
case dialogThreadLogin:
{
if(response)
{
new query[256];
new EncryptedPass[130];
WP_Hash(EncryptedPass, sizeof(EncryptedPass), inputtext);
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(query, sizeof(query), "SELECT * FROM user_accounts WHERE Username = '%s' AND Password = '%s'", pName, EncryptedPass);
mysql_query(query);
mysql_store_result();
if(mysql_num_rows() == 1)
{
LoginPlayer(playerid);
} else {
SendClientMessage(playerid, -1, "Incorrect password.");
ShowPlayerDialog(playerid, dialogThreadLogin, DIALOG_STYLE_INPUT, "Login", "Enter your password:", "Login", "Cancel");
}
}
}
Re: MySQL + Whirlpool (Saving/Loading issues) -
bgedition - 03.09.2015
Hey there,
Because of the fact that Whirlpool's hash encryption is only 129 characters long you should change your value of EncryptedPass to 129(EncryptedPass[129]) and in the database the password column should be varchar(129). Then delete your account from the database and try again. This should work without any issues.
BGEdition
Re: MySQL + Whirlpool (Saving/Loading issues) -
GXLZPGX - 03.09.2015
The register/login is returning a different value than the SavePlayer function.
/edit: By looking at the debug info I was able to pinpoint the issue in the SavePlayer function, I just removed "SET Username/Password" from the query considering neither of those change when the player disconnects anyways. I'm guessing I was hashing an already hashed password? (the hash slinging slasher)
Register/Login:
Код:
[05:57:22] >> mysql_query( Connection handle: 1 )
[05:57:22] CMySQLHandler::Query(SELECT * FROM bans WHERE (Username = 'Shadow' OR IPAddress = '') AND Status = 1) - Successfully executed.
[05:57:22] >> mysql_store_result( Connection handle: 1 )
[05:57:22] CMySQLHandler::StoreResult() - Result was stored.
[05:57:23] >> mysql_num_rows( Connection handle: 1 )
[05:57:23] CMySQLHandler::NumRows() - Returned 0 row(s)
[05:57:23] >> mysql_free_result( Connection handle: 1 )
[05:57:23] CMySQLHandler::FreeResult() - Result was successfully free'd.
[05:57:23] >> mysql_query( Connection handle: 1 )
[05:57:23] CMySQLHandler::Query(SELECT * FROM user_accounts WHERE Username = 'Shadow') - Successfully executed.
[05:57:23] >> mysql_store_result( Connection handle: 1 )
[05:57:23] CMySQLHandler::StoreResult() - Result was stored.
[05:57:23] >> mysql_num_rows( Connection handle: 1 )
[05:57:23] CMySQLHandler::NumRows() - Returned 0 row(s)
[05:57:24] >> mysql_query( Connection handle: 1 )
[05:57:24] CMySQLHandler::Query(INSERT INTO user_accounts (Username, Password, PlayerPos, Skin) VALUES ('Shadow', '310BB28AC7B16438667836D8EDB887544B49BFC6212BC1A8217F284DBD43D5F2B9ACEF89E6530C9A47B84372EB139044D5AC1D6C33D0227CDF1ADF046CFD7F3D', '1.0 2.0 3.0', '0')) - Successfully executed.
[05:57:25] >> mysql_query( Connection handle: 1 )
[05:57:25] CMySQLHandler::Query(SELECT * FROM user_accounts WHERE Username = 'Shadow') - Successfully executed.
[05:57:25] >> mysql_store_result( Connection handle: 1 )
[05:57:25] CMySQLHandler::StoreResult() - Result was stored.
[05:57:25] >> mysql_fetch_row_format( Connection handle: 1 )
[05:57:25] CMySQLHandler::FetchRow() - Return: Shadow|310BB28AC7B16438667836D8EDB887544B49BFC6212BC1A8217F284DBD43D5F2B9ACEF89E6530C9A47B84372EB139044D5AC1D6C33D0227CDF1ADF046CFD7F3D|1.0 2.0 3.0|0|0|0|0|14
[05:57:25] >> mysql_fetch_field_row( Connection handle: 1 )
[05:57:25] CMySQLHandler::FetchField("Username") - Shadow
[05:57:25] >> mysql_fetch_field_row( Connection handle: 1 )
[05:57:25] CMySQLHandler::FetchField("Password") - 310BB28AC7B16438667836D8EDB887544B49BFC6212BC1A8217F284DBD43D5F2B9ACEF89E6530C9A47B84372EB139044D5AC1D6C33D0227CDF1ADF046CFD7F3D
[05:57:25] >> mysql_fetch_field_row( Connection handle: 1 )
[05:57:25] CMySQLHandler::FetchField("PlayerPos") - 1.0 2.0 3.0
[05:57:25] >> mysql_fetch_field_row( Connection handle: 1 )
[05:57:25] CMySQLHandler::FetchField("AdminLevel") - 0
[05:57:25] >> mysql_fetch_field_row( Connection handle: 1 )
[05:57:25] CMySQLHandler::FetchField("Skin") - 0
[05:57:25] >> mysql_fetch_field_row( Connection handle: 1 )
[05:57:25] CMySQLHandler::FetchField("LoggedIn") - 0
[05:57:25] >> mysql_fetch_field_row( Connection handle: 1 )
[05:57:25] CMySQLHandler::FetchField("Money") - 0
[05:57:25] >> mysql_fetch_field_row( Connection handle: 1 )
[05:57:25] CMySQLHandler::FetchField("ID") - 14
[05:57:25] >> mysql_fetch_row_format( Connection handle: 1 )
[05:57:25] >> mysql_query( Connection handle: 1 )
SavePlayer function
Код:
[05:57:25] CMySQLHandler::Query(UPDATE user_accounts SET LoggedIn = '1' WHERE Username = 'Shadow') - Successfully executed.
[05:57:36] >> mysql_query( Connection handle: 1 )
[05:57:36] CMySQLHandler::Query(UPDATE user_accounts SET Username = 'Shadow', Password = '19FA61D75522A4669B44E39C1D2E1726C530232130D407F89AFEE0964997F7A73E83BE698B288FEBCF88E3E03C4F0757EA8964E59B63D93708B138CC42A66EB3', PlayerPos = '2059.809082 2203.632324 12.789697', AdminLevel = '0', Skin = '1', Money = '0' WHERE Username = 'Shadow') - Successfully executed.
[05:57:41] >> mysql_query( Connection handle: 1 )
[05:57:42] CMySQLHandler::Query(UPDATE user_accounts SET LoggedIn = '0' WHERE Username = 'Shadow') - Successfully executed.
[05:58:10] >> mysql_query( Connection handle: 1 )
[05:58:10] CMySQLHandler::Query(SELECT * FROM bans WHERE (Username = 'Shadow' OR IPAddress = '') AND Status = 1) - Successfully executed.
[05:58:10] >> mysql_store_result( Connection handle: 1 )
[05:58:10] CMySQLHandler::StoreResult() - Result was stored.
[05:58:10] >> mysql_num_rows( Connection handle: 1 )
[05:58:10] CMySQLHandler::NumRows() - Returned 0 row(s)
[05:58:10] >> mysql_free_result( Connection handle: 1 )
[05:58:10] CMySQLHandler::FreeResult() - Result was successfully free'd.
[05:58:10] >> mysql_query( Connection handle: 1 )
[05:58:10] CMySQLHandler::Query(SELECT * FROM user_accounts WHERE Username = 'Shadow') - Successfully executed.
[05:58:10] >> mysql_store_result( Connection handle: 1 )
[05:58:10] CMySQLHandler::StoreResult() - Result was stored.
[05:58:10] >> mysql_num_rows( Connection handle: 1 )
[05:58:10] CMySQLHandler::NumRows() - Returned 1 row(s)