Save the player password
#7

Of course. The following method would only work if the player is online though:

PHP код:
CMD:changepass(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid)) // Add your admin variable checks here
        
return SendClientMessage(playeridCOLOR_WHITE"{ff0000}[Server]:{ffffff} You ain't no admin, fool!");
        
    new
        
targetid,
        
newpass[24],
        
c_newpass[24]
    ;

    if(
sscanf(params,"us[24]s[24]"targetidnewpassc_newpass))
        return 
SendClientMessage(playerid,COLOR_WHITE,"{ff0000}[Server]:{ffffff} /setpass [user] [newpass] [newpass]");
    if(!
IsPlayerConnected(targetid) || targetid == INVALID_PLAYER_ID// Check if the player is valid
        
return SendClientMessage(playeridCOLOR_WHITE"{ff0000}[Server]:{ffffff} That player is not online.");
    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.");

    if ( 
strlen(c_newpass) && !strcmp(newpassc_newpassfalse) ) // match
    
{
        new 
query[512];
        
format(querysizeof(query), "{ff0000}[Server]:{ffffff} Your password has been changed to: %s"newpass);
        
SendClientMessage(targetidCOLOR_WHITEquery); // Notifying the player
        
SendClientMessage(playeridCOLOR_WHITE"{ff0000}[Server]:{ffffff} Password changed!");
        
GameTextForPlayer(playerid"Password changed!"50005); // Make sure you alert the player that their password is changed.
        
WP_Hash(hashsizeof(hash), newpass); // Hashing the NEW password
        
mysql_format(mysqlquerysizeof(query), "UPDATE `players` SET `Password`='%s' WHERE `ID`=%d"hashpData[targetid][ID]);
        
mysql_tquery(mysqlquery"""");
        
strmid(pData[targetid][Password], hash0strlen(hash), sizeof(hash));
        
SavePlayerData(targetid);
    }
    else 
SendClientMessage(playerid, -1"{ff0000}[Server]:{ffffff} The new passwords do not match.");
    return 
1;

You can easily change it so it works for offline players too, but that shouldn't really even be allowed tbh, because then you're essentially locking someone out of their account without telling them.
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)