PHP Code:
enum Dialog_Data // all of the data of the 'enum' initialiser, is saved in the memory.
{
DIALOG_CHANGEPS,
DIALOG_CHANGEPS2
};
As we are going to use dialogs for changing the password, I prefer using the dialog ids with 'enum' initialiser, for ease and no tension related to mixing/collision of the dialog ids.
PHP Code:
CMD:changepass(playerid, params[])
{
ShowPlayerDialog(playerid, DIALOG_CHANGEPS, DIALOG_STYLE_INPUT, "Changing Password - Step 1", "Input your current password, in order to change your password.", "Next", "Cancel"); // showing the player a dialog
return 1;
}
We have created a command using the ZCMD command processor, and we are showing the player a dialog, to enter his current password, so he/she can move on to the next and final step of changing password.
PHP Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_CHANGEPS:
{
if(response)
{
new hashpass[129]; // the whirlpool uses a 129 length string for hashing the password.
WP_Hash(hashpass, sizeof(hashpass), inputtext); // to hash the input data
if(!strcmp(hashpass, PlayerInfo[playerid][Password])) // if the password matches, continue to step 2
{
ShowPlayerDialog(playerid, DIALOG_CHANGEPS2, DIALOG_STYLE_INPUT, "Changing Password - Step 2", "Input your desired new password, in order to comple the process.", "Okay", "Cancel"); // showing the player a second and final dialog to enter his new password
}
else
{ // if the password is incorrect, re-show them to enter the current and correct password
SendClientMessage(playerid, darkred, "ERROR: You have entered an incorrect password."); // no need of explanation
ShowPlayerDialog(playerid, DIALOG_CHANGEPS, DIALOG_STYLE_INPUT, "Changing Password - Step 1", "Input your current password, in order to change your password.", "Next", "Cancel"); // showing player the dialog to enter his correct and current password
}
}
return 1;
} // end of the dialog part one
read the commented lines in the code above.
PHP Code:
case DIALOG_CHANGEPS2:
{
if(response)
{
if(!strlen(inputtext)) // if nothing is entered in the dialog
{
return SendClientMessage(playerid, darkred, "ERROR: You must enter a password.");
}
new string[128];
format(string, sizeof(string), "Your password is: %s", inputtext); // we have formatted a string to include variables inside it
SendClientMessage(playerid, -1, string); // sending the above string message
new INI:file = INI_Open(UserPath(playerid)); // opened the player's save file
WP_Hash(PlayerInfo[playerid][Password], 129, inputtext); // hashed the password in the player enum
INI_WriteString(file, "Password", PlayerInfo[playerid][Password]); // replaced the old hashed password with the new one
INI_Close(file);
return 1;
}
}
}
return 0;
} // On Dialog Response code end
Read the commented lines in the code above.