/changepass command using sscanf
#2

First of all, specific to your inquiry about sscanf, you should specify the length of each string by encapsulating the maximum size in square brackets. For example, if the maximum length of each string is 24 characters, you would use

Код:
if(sscanf(params, "s[24]s[24]", oldpass, newpass))
instead of
Код:
if(sscanf(params, "ss", oldpass, newpass))
that aside, you are initializing oldpass and newpass as single cells, not cell arrays. If the maximum length of the password would be 24 characters, you should change:

Код:
new name[MAX_PLAYER_NAME], file[128], tmp, oldpass, newpass;
into
Код:
new name[MAX_PLAYER_NAME], file[128], tmp, oldpass[24], newpass[24];
Finally, you are trying to rehash the stored password.

Edit:
In conclusion, changing
Код:
COMMAND:changepass(playerid, params[])
{
    new name[MAX_PLAYER_NAME], file[128], tmp, oldpass, newpass;
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), UserFile, name);
    if(sscanf(params, "ss", oldpass, newpass)) return SendClientMessage(playerid, COLOR_SYSTEMRED, "USAGE: /changepass <oldpass> <newpass>");
    tmp = djInt(file, "Password");
    if(udb_hash(tmp) == oldpass)
    {
        djSetInt(file, "Password", udb_hash(newpass));
        SendClientMessage(playerid, COLOR_GREEN, "( ! ) Password change successful");
    }
    else SendClientMessage(playerid, COLOR_SYSTEMRED, "( ! ) The old password you entered is incorrect");
    return 1;
}
to

Код:
COMMAND:changepass(playerid, params[])
{
    new name[ MAX_PLAYER_NAME ], file[ 128 ], tmp, oldpass[ 24 ], newpass[ 24 ];
    GetPlayerName( playerid, name, MAX_PLAYER_NAME );
    format( file, sizeof(file), UserFile, name );

    if( sscanf(params, "s[24]s[24]", oldpass, newpass ) )
        return SendClientMessage( playerid, COLOR_SYSTEMRED, "USAGE: /changepass <oldpass> <newpass>" );
   
    tmp = djInt( file, "Password" );
    if( tmp == udb_hash( oldpass ) )
    {
        djSetInt( file, "Password", udb_hash( newpass ) );
        SendClientMessage( playerid, COLOR_GREEN, "( ! ) Password change successful" );
    }
    else
        SendClientMessage( playerid, COLOR_SYSTEMRED, "( ! ) The old password you entered is incorrect" );
    
return 1;
}
Reply


Messages In This Thread
/changepass command using sscanf - by sim_sima - 30.06.2011, 11:55
Re: /changepass command using sscanf - by langricr - 30.06.2011, 12:27
Re: /changepass command using sscanf - by sim_sima - 30.06.2011, 12:46
Re: /changepass command using sscanf - by langricr - 30.06.2011, 12:47
Re: /changepass command using sscanf - by sim_sima - 30.06.2011, 12:58
Re: /changepass command using sscanf - by sim_sima - 30.06.2011, 13:29
Re: /changepass command using sscanf - by playbox12 - 30.06.2011, 13:33
Re: /changepass command using sscanf - by sim_sima - 30.06.2011, 13:37

Forum Jump:


Users browsing this thread: 1 Guest(s)