Login/register system help.
#1

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.
Reply
#2

Here is an exemple

PHP код:
case DIALOG_LOGIN:
        {
            
//if(!response) return Kick(playerid);
            //if(response)
            
switch(response)
            {
                case 
0Kick(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(playeridplayernamesizeof(playername));
                        
PlayerInfo[playerid][pName] = playername;
                        
TogglePlayerSpectating(playeridfalse);
                        new 
INI:File INI_Open(UserPath(playerid));
                        
INI_SetTag(File,"Account Info");
                        
INI_WriteString(File"Name"PlayerInfo[playerid][pName]);
                        
INI_Close(File);
                        
ShowPlayerDialog(playeridDIALOG_SUCCESS_2DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
                           if(
PlayerInfo[playerid][pBan] == 1)
                        {
                            
SendClientMessage(playeridCOLOR_LIGHTRED"You have been banned for logging into a banned account.");
                            
SetTimerEx("UnsetBan"5000"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 GetPVarInt(playerid"WrongPassword");
                              
format(stringsizeof(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;
                 }
             }
        }
    } 
Reply
#3

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.
Reply
#4

- 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
Reply
#5

Ok guyz,i'ill try it.Thanks
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)