28.05.2018, 21:14
Ok i fixed in this way but...
Now i can login even if the account doesn't exist. What's wrong?
For reference, this is the login dialog where if user types the correct password, he logins:
pawn Код:
function OnPlayerDataLoaded(playerid, race_check)
{
if (race_check != g_MysqlRaceCheck[playerid]) return Kick(playerid);
new string[115];
if (!strcmp(Player[playerid][LastIP], ReturnPlayerIp(playerid), true))
{
cache_set_active(Player[playerid][Cache_ID]);
AssignPlayerData(playerid);
cache_delete(Player[playerid][Cache_ID]);
Player[playerid][Cache_ID] = MYSQL_INVALID_CACHE;
KillTimer(Player[playerid][LoginTimer]);
Player[playerid][LoginTimer] = 0;
Player[playerid][IsLoggedIn] = true;
}
else if(cache_num_rows() > 0)
{
cache_get_value(0, "password", Player[playerid][Password], 65);
cache_get_value(0, "salt", Player[playerid][Salt], 17);
Player[playerid][Cache_ID] = cache_save();
format(string, sizeof string, "This account (%s) is registered. Please login by entering your password in the field below:", Player[playerid][Name]);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", string, "Login", "Abort");
Player[playerid][LoginTimer] = SetTimerEx("OnLoginTimeout", SECONDS_TO_LOGIN * 1000, false, "d", playerid);
}
else
{
format(string, sizeof string, "Welcome %s, you can register by entering your password in the field below:", Player[playerid][Name]);
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registration", string, "Register", "Abort");
}
return 1;
}
For reference, this is the login dialog where if user types the correct password, he logins:
pawn Код:
case DIALOG_LOGIN:
{
if (!response) return Kick(playerid);
new hashed_pass[65];
SHA256_PassHash(inputtext, Player[playerid][Salt], hashed_pass, 65);
if (strcmp(hashed_pass, Player[playerid][Password]) == 0)
{
cache_set_active(Player[playerid][Cache_ID]);
AssignPlayerData(playerid);
cache_delete(Player[playerid][Cache_ID]);
Player[playerid][Cache_ID] = MYSQL_INVALID_CACHE;
KillTimer(Player[playerid][LoginTimer]);
Player[playerid][LoginTimer] = 0;
Player[playerid][IsLoggedIn] = true;
}