25.07.2016, 13:09
That's because you never actually hash the new password. You only hash the old password to see if the passwords match. So you were essentially updating the player's password with their old/current password... effectively making no changes.
Also, I couldn't find a use for 'playername' so I removed it and fixed a few typos.
Another thing I should mention, 'strcmp' returns 0 if either of the strings are empty. So I had to change this line:
Just in case.
https://sampwiki.blast.hk/wiki/Strcmp
PHP код:
CMD:changepass(playerid, params[])
{
new
hash[129],
oldpass[24],
newpass[24],
c_newpass[24]
;
if(sscanf(params,"s[24]s[24]s[24]", oldpass, newpass, c_newpass))
return SendClientMessage(playerid,COLOR_WHITE,"{ff0000}[Server]:{ffffff} /changepass [currentpass] [newpass] [newpass]");
if (strlen(newpass) > MAX_PLAYER_PASSWORD)
return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Server]:{ffffff} password can be a maximum of 16 characters.");
if (strlen(newpass) < MIN_PLAYER_PASSWORD)
return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Server]:{ffffff} password needs to be at least 6 characters.");
WP_Hash(hash, sizeof (hash), oldpass); // Hashing the OLD password
if ( !strcmp(hash, pData[playerid][Password], false) ) // The NEW hash does match the old (saved) one
{
if ( strlen(c_newpass) && !strcmp(newpass, c_newpass, false) ) // match
{
SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Server]:{ffffff} Password changed!");
WP_Hash(hash, sizeof(hash), newpass); // Hashing the NEW password
new query[512];
mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET `Password`='%s' WHERE `ID`=%d", hash, pData[playerid][ID]);
mysql_tquery(mysql, query, "", "");
strmid(pData[playerid][Password], hash, 0, strlen(hash), sizeof(hash));
SavePlayerData(playerid);
return 1;
}
else SendClientMessage(playerid, -1, "{ff0000}[Server]:{ffffff} Your new passwords do not match.");
}
else SendClientMessage(playerid, -1, "{ff0000}[Server]:{ffffff} Your current password does not match.");
return 1;
}
Another thing I should mention, 'strcmp' returns 0 if either of the strings are empty. So I had to change this line:
PHP код:
if ( strlen(c_newpass) && !strcmp(newpass, c_newpass, false) ) // match
https://sampwiki.blast.hk/wiki/Strcmp