Login/register system help. -
RedSmokeR - 08.06.2016
Hi guyz,i have made login/register system but i want that if player writes incorrect password 3 times,he will be kicked automatically for incorrect passwords attempts.
Re: Login/register system help. -
N0FeaR - 08.06.2016
Here is an exemple
PHP код:
case DIALOG_LOGIN:
{
//if(!response) return Kick(playerid);
//if(response)
switch(response)
{
case 0: Kick(playerid);
case 1:
{
if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
PlayerLogged[playerid] = true;
new playername[24];
GetPlayerName(playerid, playername, sizeof(playername));
PlayerInfo[playerid][pName] = playername;
TogglePlayerSpectating(playerid, false);
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"Account Info");
INI_WriteString(File, "Name", PlayerInfo[playerid][pName]);
INI_Close(File);
ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
if(PlayerInfo[playerid][pBan] == 1)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "You have been banned for logging into a banned account.");
SetTimerEx("UnsetBan", 500, 0, "i", playerid);
}
}
else
{
if(GetPVarInt(playerid, "WrongPassword") >= 5)
{
SendClientMessage(playerid,COLOR_LIGHTRED,"You have been banned for entering the wrong password in five times.");
//BanExtra(playerid,"Wrong Password","Anna-Bot");
//format(string, sizeof(string), "%s was banned for Wrong Password by Anna-Bot System.", PlayerName(playerid));
//BanLog(string);
}
else
{
new string[100];
SetPVarInt(playerid, "WrongPassword", 1+GetPVarInt(playerid, "WrongPassword"));
new amount = 5 - GetPVarInt(playerid, "WrongPassword");
format(string, sizeof(string),"Invalid password (%d tries left).", amount);
SendClientMessage(playerid,COLOR_LIGHTRED,string);
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Server Account","An existing account is using your playername, please login to the account.\nIf you can't support this dialog select the (next) option.","Login", "Next");
//ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"Login","You have entered an incorrect password.\n""Type your password below to login.","Login","Quit");
//WrongPassword(playerid);
}
}
return 1;
}
}
}
}
Re: Login/register system help. -
Lucky13 - 08.06.2016
On top of your script:
Код:
new gLoginAttempts[MAX_PLAYERS];
OnPlayerConnect & OnPlayerDisconnect:
Код:
gLoginAttempts[playerid]=0;
Now put this code where you have the incorrect password:
Код:
gLoginAttempts[playerid]++;
if(gLoginAttempts[playerid] == 3) return Kick(playerid);
And when they login successfully:
Код:
gLoginAttempts[playerid]=0; // We reset them in case he managed to login from the 2nd attempt.
Re: Login/register system help. -
Sime30 - 08.06.2016
- You create an int player-variable.
pawn Код:
new LoginAttempts[MAX_PLAYERS];
- You increase it's value everytime a player writes a wrong password.
pawn Код:
LoginAttempts[playerid]++;
- You check if the player wrote his password wrong for 3 times.
pawn Код:
if(LoginAttempts[playerid] == 3)
Also, reset this player-variable OnPlayerConnect
pawn Код:
LoginAttempts[playerid] = 0;
EDIT: Too many of you replied
Re: Login/register system help. -
RedSmokeR - 08.06.2016
Ok guyz,i'ill try it.Thanks