Save the player password
#2

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.

PHP код:
CMD:changepass(playeridparams[])
{
    new
        
hash[129],
        
oldpass[24],
        
newpass[24],
        
c_newpass[24]
    ;
    if(
sscanf(params,"s[24]s[24]s[24]"oldpassnewpassc_newpass))
        return 
SendClientMessage(playerid,COLOR_WHITE,"{ff0000}[Server]:{ffffff} /changepass [currentpass] [newpass] [newpass]");
    if (
strlen(newpass) > MAX_PLAYER_PASSWORD)
        return 
SendClientMessage(playeridCOLOR_WHITE"{ff0000}[Server]:{ffffff} password can be a maximum of 16 characters.");
    if (
strlen(newpass) < MIN_PLAYER_PASSWORD)
        return 
SendClientMessage(playeridCOLOR_WHITE"{ff0000}[Server]:{ffffff} password needs to be at least 6 characters.");
        
    
WP_Hash(hashsizeof (hash), oldpass); // Hashing the OLD password
    
if ( !strcmp(hashpData[playerid][Password], false) ) // The NEW hash does match the old (saved) one
    
{
        if ( 
strlen(c_newpass) && !strcmp(newpassc_newpassfalse) ) // match
        
{
            
SendClientMessage(playeridCOLOR_WHITE"{ff0000}[Server]:{ffffff} Password changed!");
            
WP_Hash(hashsizeof(hash), newpass); // Hashing the NEW password
            
new query[512];
            
mysql_format(mysqlquerysizeof(query), "UPDATE `players` SET `Password`='%s' WHERE `ID`=%d"hashpData[playerid][ID]);
            
mysql_tquery(mysqlquery"""");
            
strmid(pData[playerid][Password], hash0strlen(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;

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:
PHP код:
if ( strlen(c_newpass) && !strcmp(newpassc_newpassfalse) ) // match 
Just in case.
https://sampwiki.blast.hk/wiki/Strcmp
Reply


Messages In This Thread
Save the player password - by yvoms - 25.07.2016, 12:59
Re: Save the player password - by Threshold - 25.07.2016, 13:09
Re: Save the player password - by yvoms - 25.07.2016, 13:10
Re: Save the player password - by yvoms - 25.07.2016, 14:55
Re: Save the player password - by Threshold - 25.07.2016, 16:17
Re: Save the player password - by yvoms - 25.07.2016, 17:11
Re: Save the player password - by Threshold - 25.07.2016, 17:53
Re: Save the player password - by yvoms - 25.07.2016, 20:34
Re: Save the player password - by Threshold - 26.07.2016, 03:48
Re: Save the player password - by yvoms - 26.07.2016, 09:51

Forum Jump:


Users browsing this thread: 1 Guest(s)