30.06.2011, 12:27
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
instead of
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:
into
Finally, you are trying to rehash the stored password.
Edit:
In conclusion, changing
to
Код:
if(sscanf(params, "s[24]s[24]", oldpass, newpass))
Код:
if(sscanf(params, "ss", oldpass, newpass))
Код:
new name[MAX_PLAYER_NAME], file[128], tmp, oldpass, newpass;
Код:
new name[MAX_PLAYER_NAME], file[128], tmp, oldpass[24], newpass[24];
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;
}
Код:
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;
}

