15.09.2012, 10:55
Everytime i type the correct answer in the question it says "Try again error occur" which means wrong password.
Here is my code.
Note i store the question and player's password to SetPVarString so that i can save the player's pass without having problems. And can get the current question that was input by the player.
Ex.
I register.
I put the security question, "who are you?"
and the answer is "romel"
i relog and put wrong password 3x.
And then i type "romel" on the question but it says "Try again error occur"
Help me.
Here is my code.
Note i store the question and player's password to SetPVarString so that i can save the player's pass without having problems. And can get the current question that was input by the player.
Ex.
I register.
I put the security question, "who are you?"
and the answer is "romel"
i relog and put wrong password 3x.
And then i type "romel" on the question but it says "Try again error occur"
pawn Код:
//Dialog - Register
if(dialogid == REGISTER)
{
new str[128];
if(!response)
{
format(str, sizeof(str), "Kick: %s(id:%d) has been kicked (Reason: Not Regestering)", GetName(playerid), playerid);
SendClientMessageToAll(COLOR_GREY, str);
return Kick(playerid);
}
if(response)
{
if(!strlen(inputtext))
{
ShowPlayerDialog(playerid, REGISTER, DIALOG_STYLE_PASSWORD, ""white"RomAdmin - Register", "Welcome to the Server,\nPlease register first by\nPutting your password below\n"red"You left the password field BLANK!", "Register", "Exit");
return 1;
}
WP_Hash(hash, sizeof(hash), inputtext);
new INI:file = INI_Open(Path(playerid));
INI_SetTag(file, "account");
SetPVarString(playerid, "MyPass", hash);
GetPlayerIp(playerid, PlayerAcc[playerid][Ip], 16);
INI_WriteString(file, "Password", hash);
INI_WriteString(file, "Ip", PlayerAcc[playerid][Ip]);
INI_WriteString(file, "SecurityQuestion", "N/A");
INI_WriteString(file, "Answer", "N/A");
PlayerAcc[playerid][Cookies] = 1;
INI_WriteInt(file, "Cookies", PlayerAcc[playerid][Cookies]);
PlayerAcc[playerid][SaveSkin] = 0; //0 = CJ so if player /useskin it will load the skin Cj
INI_WriteInt(file, "SaveSkin", PlayerAcc[playerid][SaveSkin]);
PlayerAcc[playerid][UseSkin] = 0;
INI_WriteInt(file, "UseSkin", PlayerAcc[playerid][UseSkin]);
PlayerAcc[playerid][Jail] = 0;
INI_WriteInt(file, "Jail", PlayerAcc[playerid][Jail]);
PlayerAcc[playerid][Mute] = 0;
INI_WriteInt(file, "Mute", PlayerAcc[playerid][Mute]);
PlayerAcc[playerid][MuteTime] = 0;
INI_WriteInt(file, "MuteTime", PlayerAcc[playerid][MuteTime]);
PlayerAcc[playerid][Admin] = 0;
INI_WriteInt(file, "Admin", PlayerAcc[playerid][Admin]);
PlayerAcc[playerid][Vip] = 0;
INI_WriteInt(file, "Vip", PlayerAcc[playerid][Vip]);
PlayerAcc[playerid][WantedLvl] = 0;
SetPlayerWantedLevel(playerid, PlayerAcc[playerid][WantedLvl]);
INI_WriteInt(file, "WantedLevel", PlayerAcc[playerid][WantedLvl]);
PlayerAcc[playerid][Score] = 1;
SetPlayerScore(playerid, PlayerAcc[playerid][Score]);
INI_WriteInt(file, "Score", PlayerAcc[playerid][Score]);
PlayerAcc[playerid][Money] = 5000;
GivePlayerMoney(playerid, PlayerAcc[playerid][Money]);
INI_WriteInt(file, "Money", PlayerAcc[playerid][Money]);
PlayerAcc[playerid][Kills] = 0;
INI_WriteInt(file, "Kills", PlayerAcc[playerid][Kills]);
PlayerAcc[playerid][Deaths] = 1;
INI_WriteInt(file, "Deaths", PlayerAcc[playerid][Deaths]);
INI_Close(file);
PlayerAcc[playerid][Log] = 1;
format(str, sizeof(str), "Success: You've successfully register and login with password '%s'", inputtext);
SendClientMessage(playerid, COLOR_YELLOW, str);
ShowPlayerDialog(playerid, CQUESTION, DIALOG_STYLE_INPUT, ""white"Security Question", ""white"Please ignore this if you don't want\na security question to your account\nPut the question will be display when player puts\nwrong password 3 times", "Put", "Ignore");
return 1;
}
}
//Dialog - Login
if(dialogid == LOGIN)
{
new str[128], str2[256];
if(!response)
{
format(str, sizeof(str), "Kick: %s(id:%d) has been kicked (Reason: Not Logging In)", GetName(playerid), playerid);
SendClientMessageToAll(COLOR_GREY, str);
return Kick(playerid);
}
if(response)
{
WP_Hash(hash, sizeof(hash), inputtext);
if(!strcmp(hash, PlayerAcc[playerid][Pass]))
{
INI_ParseFile(Path(playerid),"loadaccount_user", .bExtra = true, .extra = playerid);
if(ServerInfo[ScoreSaving] == 1)
{
SetPlayerScore(playerid, PlayerAcc[playerid][Score]);
}
SetPlayerWantedLevel(playerid, PlayerAcc[playerid][WantedLvl]);
GivePlayerMoney(playerid, PlayerAcc[playerid][Money]);
SendClientMessage(playerid, COLOR_YELLOW, "Success: You've successfully login to your account");
PlayerAcc[playerid][Log] = 1;
}
else
{
if(PlayerAcc[playerid][Warn] == MAX_WARNINGS)
{
if(strcmp(PlayerAcc[playerid][Question], "N/A", true) == 0)
{
format(str, sizeof(str), "Kick: %s(id:%d) has been kicked (Reason: Attempting to Login with wrong answer on SQ)", GetName(playerid), playerid);
SendClientMessageToAll(COLOR_GREY, str);
return Kick(playerid);
}
else
{
format(str2, sizeof(str2), ""white"%s\nAnswer it to Access the Account", PlayerAcc[playerid][Question]);
ShowPlayerDialog(playerid, QUESTION, DIALOG_STYLE_INPUT, ""white"Question", str2, "Answer", "Quit");
PlayerAcc[playerid][Warn] = 0;
}
return 0;
}
ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_PASSWORD, ""white"RomAdmin - Login", "Welcome Back,\nPlease login first by\nPutting your password below\n"red"You put a incorrect password!, Try Again", "Login", "Exit");
PlayerAcc[playerid][Warn] += 1;
return 1;
}
}
}
//Dialog - Add Security Question
if(dialogid == CQUESTION)
{
new pass[129], str[129];
if(!response) return SendClientMessage(playerid, COLOR_YELLOW, "You decide to not install the Security Question to your account!");
else if(response)
{
if(!strlen(inputtext))
{
ShowPlayerDialog(playerid, CQUESTION, DIALOG_STYLE_INPUT, ""white"Security Question", ""white"Please ignore this if you don't want\na security question to your account\nPut the question will be display when player puts\nwrong password 3 times\n"red"Try again error occur!", "Put", "Ignore");
return 1;
}
GetPVarString(playerid, "MyPass", pass, sizeof(pass));
new INI:file = INI_Open(Path(playerid));
INI_SetTag(file, "account");
INI_WriteString(file, "Password", pass);
INI_WriteString(file, "Ip", PlayerAcc[playerid][Ip]);
SetPVarString(playerid, "MyQues", inputtext);
format(str, sizeof(str), "%s", inputtext);
PlayerAcc[playerid][Question] = str;
INI_WriteString(file, "SecurityQuestion", inputtext);
INI_WriteString(file, "Answer", "N/A");
INI_WriteInt(file, "Cookies", PlayerAcc[playerid][Cookies]);
INI_WriteInt(file, "SaveSkin", PlayerAcc[playerid][SaveSkin]);
INI_WriteInt(file, "UseSkin", PlayerAcc[playerid][UseSkin]);
INI_WriteInt(file, "Jail", PlayerAcc[playerid][Jail]);
INI_WriteInt(file, "Mute", PlayerAcc[playerid][Mute]);
INI_WriteInt(file, "MuteTime", PlayerAcc[playerid][MuteTime]);
INI_WriteInt(file, "Admin", PlayerAcc[playerid][Admin]);
INI_WriteInt(file, "Vip", PlayerAcc[playerid][Vip]);
INI_WriteInt(file, "WantedLevel", PlayerAcc[playerid][WantedLvl]);
INI_WriteInt(file, "Score", PlayerAcc[playerid][Score]);
INI_WriteInt(file, "Money", PlayerAcc[playerid][Money]);
INI_WriteInt(file, "Kills", PlayerAcc[playerid][Kills]);
INI_WriteInt(file, "Deaths", PlayerAcc[playerid][Deaths]);
INI_Close(file);
ShowPlayerDialog(playerid, ANSWER, DIALOG_STYLE_INPUT, ""white"Answer", ""white"Last Step\nPut the answer for your security question", "Put", "");
}
}
if(dialogid == ANSWER)
{
new str[129], pass[129];
if(response)
{
if(!strlen(inputtext))
{
ShowPlayerDialog(playerid, ANSWER, DIALOG_STYLE_INPUT, ""white"Answer", ""white"Last Step\nPut the answer for your security question\n"red"Try again error occur!", "Put", "");
return 1;
}
new ques[129];
GetPVarString(playerid, "MyQues", ques, 129);
GetPVarString(playerid, "MyPass", pass, sizeof(pass));
WP_Hash(hash, sizeof(hash), inputtext);
new INI:file = INI_Open(Path(playerid));
INI_SetTag(file, "account");
INI_WriteString(file, "Password", pass);
INI_WriteString(file, "Ip", PlayerAcc[playerid][Ip]);
INI_WriteString(file, "SecurityQuestion", ques);
format(str, sizeof(str), "%s", hash);
PlayerAcc[playerid][Answer] = str;
INI_WriteString(file, "Answer", hash);
INI_WriteInt(file, "Cookies", PlayerAcc[playerid][Cookies]);
INI_WriteInt(file, "SaveSkin", PlayerAcc[playerid][SaveSkin]);
INI_WriteInt(file, "UseSkin", PlayerAcc[playerid][UseSkin]);
INI_WriteInt(file, "Jail", PlayerAcc[playerid][Jail]);
INI_WriteInt(file, "Mute", PlayerAcc[playerid][Mute]);
INI_WriteInt(file, "MuteTime", PlayerAcc[playerid][MuteTime]);
INI_WriteInt(file, "Admin", PlayerAcc[playerid][Admin]);
INI_WriteInt(file, "Vip", PlayerAcc[playerid][Vip]);
INI_WriteInt(file, "WantedLevel", PlayerAcc[playerid][WantedLvl]);
INI_WriteInt(file, "Score", PlayerAcc[playerid][Score]);
INI_WriteInt(file, "Money", PlayerAcc[playerid][Money]);
INI_WriteInt(file, "Kills", PlayerAcc[playerid][Kills]);
INI_WriteInt(file, "Deaths", PlayerAcc[playerid][Deaths]);
INI_Close(file);
format(str, sizeof(str), "You set the answer for your security question '%s' is '%s'", ques, inputtext);
SendClientMessage(playerid, COLOR_LIME, str);
}
}
if(dialogid == QUESTION)
{
new str[256];
if(!response)
{
format(str, sizeof(str), "Kick: %s(id:%d) has been kicked (Reason: Quiting instead Answering Security Question)", GetName(playerid), playerid);
SendClientMessageToAll(COLOR_GREY, str);
return Kick(playerid);
}
if(response)
{
WP_Hash(hash, sizeof(hash), inputtext);
if(!strcmp(PlayerAcc[playerid][Answer], hash))
{
INI_ParseFile(Path(playerid),"loadaccount_user", .bExtra = true, .extra = playerid);
if(ServerInfo[ScoreSaving] == 1)
{
SetPlayerScore(playerid, PlayerAcc[playerid][Score]);
}
SetPlayerWantedLevel(playerid, PlayerAcc[playerid][WantedLvl]);
GivePlayerMoney(playerid, PlayerAcc[playerid][Money]);
SendClientMessage(playerid, COLOR_YELLOW, "Success: You've successfully login to your account with Security Question");
PlayerAcc[playerid][Log] = 1;
}
else
{
format(str, sizeof(str), ""white"%s\nAnswer it to Access the Account\n"red"Try again error occur!", PlayerAcc[playerid][Question]);
ShowPlayerDialog(playerid, QUESTION, DIALOG_STYLE_INPUT, ""white"Question", str, "Answer", "Quit");
}
}
}