if(dialogid == REGISTER_LOGIN)
{
if(!response) return Kick(playerid);
if(response)
{
new hashpass[129];
WP_Hash(hashpass,sizeof(hashpass),inputtext);
if(!strcmp(hashpass, pInfo[playerid][pPass], false))
{
INI_ParseFile(Path(playerid),"LoadAccount_%s",.bExtra = true, .extra = playerid);
SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");
}
else
{
ShowPlayerDialog(playerid,REGISTER_LOGIN,DIALOG_STYLE_INPUT,"Login","Incorrect Password.","Login","Quit");
return 1;
}
}
}
if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
new HashPass[128];
WP_Hash(HashPass, sizeof(HashPass), inputtext);
if(!strcmp(HashPass, pInfo[playerid][pPass])) {
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
} else {
ShowPlayerDialog(playerid,REGISTER_LOGIN,DIALOG_STYLE_INPUT,"Login","Incorrect Password.","Login","Quit");
return 1;
}
Make sure you load the player's password into pInfo before you compare the strings because strcmp will return 0 (aka say the strings match) if one of the strings is empty. So if you don't load the password before you compare them then pInfo[playerid][pPass] will be empty and it will accept any password.
|
enum PlayerInfo
{
pPass[128],
pKills,
pDeaths,
pVip,
pAdmin
}
pawn Код:
|
This works perfectly for me.
pawn Код:
|
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == REGISTER_REGISTER)
{
if(!response)
{
Kick(playerid);
}
if(response)
{
if(!strlen(inputtext))
{
SCM(playerid,COLOR_RED, "You must enter a password to register a account.");
ShowPlayerDialog(playerid, REGISTER_REGISTER, DIALOG_STYLE_INPUT, "Please register a account.", "Register", "Enter", "Leave");
return 1;
}
new hashpass[129];
WP_Hash(hashpass,sizeof(hashpass),inputtext);
new INI:file = INI_Open(Path(playerid));
INI_SetTag(file, "Player Data");
INI_WriteString(file,"Password",hashpass);
INI_WriteInt(file, "Kills", 0);
INI_WriteInt(file, "Deaths", 0);
INI_WriteInt(file, "Vip", 0);
INI_WriteInt(file, "Admin", 0);
INI_Close(file);
new string[128];
format(string,sizeof(string), "You've registered at Highschool Roleplay with the password %s", inputtext);
SCM(playerid,COLOR_GREEN, string);
ShowPlayerDialog(playerid,REGISTER_LOGIN,DIALOG_STYLE_INPUT,"Login","Enter your password to login.","Login","Quit");
}
}
if(dialogid == REGISTER_LOGIN)
{
if(!response) return Kick(playerid);
if(response)
{
new hashpass[129];
WP_Hash(hashpass,sizeof(hashpass),inputtext);
if(!strcmp(hashpass, pInfo[playerid][pPass]))
{
INI_ParseFile(Path(playerid),"LoadAccount_%s",.bExtra = true, .extra = playerid);
SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");
}
else
{
ShowPlayerDialog(playerid,REGISTER_LOGIN,DIALOG_STYLE_INPUT,"Login","Incorrect Password.","Login","Quit");
return 1;
}
}
}
return 1;
}