12.03.2017, 14:48
Im using sha256 for password hashing, but when someone chnagepassword and reconnect, it's say wrong password
changepassword command:
It's same thing on the changeplayerpassword , but changeplayerpassword command works but changepassword coomad not
I rework the comand 5 times, but never work correct , i was used temp variabiles , player variabiles but it's not work
changepassword command:
PHP код:
CMD:changepassword(playerid, params[])
{
new query[264], string[264], newpass[64];
if(sscanf(params, "s[64]", newpass)) return SendClientMessage(playerid, -1, "Use: /changepassword [new password]");
if(strlen(newpass) < 5) return SendClientMessage(playerid, 3, "The password need to be at least 5 characters.");
format(string, sizeof (string), "You've change your password in: %s.Keep it safe!", newpass);
SendClientMessage(playerid, -1, string);
for (new i = 0; i < 16; i++) APlayerData[playerid][Salt][i] = random(94) + 33;
SHA256_PassHash(newpass, APlayerData[playerid][Salt], APlayerData[playerid][PlayerPassword], 65);
mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `password`= '%e',`salt` = '%e' WHERE `username` = '%e'", APlayerData[playerid][PlayerPassword],APlayerData[playerid][Salt],pName(playerid));
mysql_tquery(g_SQL, query);
return 1;
}
PHP код:
CMD:changeplayerpassword(playerid,params[])
{
LevelCheck(playerid,8);
new name[MAX_PLAYER_NAME],query[264],pass[64],hasshed_password[64],salt[16];
if(sscanf(params,"s[24]s[64]",name,pass)) return SendClientMessage(playerid, -1, "Use: /changepalyerpassword <ExactName> <password>");
if(strlen(pass) < 5) return SendClientMessage(playerid, 3, "The password need to be at least 5 characters.");
for (new i = 0; i < 16; i++) salt[i] = random(94) + 33;
SHA256_PassHash(pass, salt, hasshed_password, 64);
mysql_format(g_SQL, query, sizeof(query), "UPDATE `players` SET `password` = '%e',`salt` = '%e' WHERE `username` = '%e' LIMIT 1", hasshed_password,salt,name);
mysql_tquery(g_SQL, query, "","");
return 1;
}