Password lenght when registering
#1

How do i make if the password has <6 and >20 words and that shows a warning?
Код:
if(dialogid==REGISTRACIJA)
	{
		if(response==0)
		{
			ShowPlayerDialog(playerid,1,DIALOG_STYLE_MSGBOX,"{FF0000}                  GREЉKA","{FF0000}_______________________________\n\n      Odustali ste od registracije pa\n\n          ste izbaceni sa servera!\n\n_______________________________","Izadi","");
			Kick(playerid);
			return 1;
		}
		if(response==1)
		{
			if(!strlen(inputtext))
			{
				ShowPlayerDialog(playerid,REGISTRACIJA,DIALOG_STYLE_PASSWORD,"{FF0000}                 Registracija","{FF0000}_______________________________\n\n      Molim unesite zeljenu lozinku:\n_______________________________","Registriraj","Odustani");
			}
			else
			{
				Registracija(playerid,inputtext);
				return 1;
			}
		}
	}
the stock is

Код:
stock Registracija(playerid,key[])
{
	new datoteka[64];
	new name[MAX_PLAYER_NAME];
	GetPlayerName(playerid,name,sizeof(name));
	format(datoteka,sizeof(datoteka),"/korisnici/%s.txt",name);
	dini_Create(datoteka);
	dini_Set(datoteka,"Lozinka",key);
	SetPlayerScore(playerid,0);
	return 1;
}
Reply
#2

Add if(strlen(inputtext)) >= YOUR_AMOUNT && strlen(inputtext)) <= YOUR_AMOUNT)

That should work.
Reply
#3

And indeed there's a better way to check this. ****** once found out that unlike C, syntax like
pawn Код:
if(!(6 <= strlen(inputtext) <= 20)) // warning!
is valid as well.

The code above will be true if the length of inputtext is either below 6 or above 20.

What's better about it? Only one function call, not 2.
Reply
#4

Yeah,this works

Код:
		if(response==1)
		{
			if(strlen(inputtext) < 6 )
			{
				ShowPlayerDialog(playerid,REGISTRACIJA,DIALOG_STYLE_PASSWORD,"{FF0000}                 Registracija","{FF0000}_______________________________\n\n      Molim unesite zeljenu lozinku:\n_______________________________","Registriraj","Odustani");
				SendClientMessage(playerid,CRVENA,"Lozinka moћe imati najmanje 6 a najviљse 20 znakova!");
			}
			if(strlen(inputtext) > 20 )
			{
				ShowPlayerDialog(playerid,REGISTRACIJA,DIALOG_STYLE_PASSWORD,"{FF0000}                 Registracija","{FF0000}_______________________________\n\n      Molim unesite zeljenu lozinku:\n_______________________________","Registriraj","Odustani");
				SendClientMessage(playerid,CRVENA,"Lozinka moћe imati najmanje 6 a najviљse 20 znakova!");
			}
			else
			{
				Registracija(playerid,inputtext);
				return 1;
			}
		}
Anyway how do you kick a player if he enters the password 3 times wrong?


Код:
	if(dialogid==LOGIRANJE)
	{
		if(response==0)
		{
			ShowPlayerDialog(playerid,1,DIALOG_STYLE_MSGBOX,"{FF0000}                  GREЉKA","{FF0000}_______________________________\n\n      Odustali ste od logiranja pa\n\n           ste izbaceni  sa servera!\n\n_______________________________","Izadi","");
			for(new i = 0; i < 50; i++) SendClientMessageToAll(BIJELA," ");
			Kick(playerid);
			return 1;  //this kicks the player if he clicks cancel
		}
		if(response==1)
		{
			if(!strlen(inputtext))
			{
				for(new i = 0; i < 50; i++) SendClientMessageToAll(BIJELA," "); //cleans chat
				ShowPlayerDialog(playerid,LOGIRANJE,DIALOG_STYLE_PASSWORD,"{FF0000}                  PRIJAVA","{00FF00}_______________________________\n\n         Vaљ Acount je pronaden!\n\n      Molimo unesite vaљu lozinku:\n_______________________________","Logiraj","Odustani");
				SendClientMessage(playerid,CRVENA,"Unjeli ste pogreљnu lozinku!"); // you entered the wrong password
			}
			else
			{
				Login(playerid,inputtext); //login
				return 1;
			}
		}
	}
Reply
#5

You send exactly the same message and open the same dialog when the player enters more than 20 or less than 6 characters. Why not follow the example that I gave you instead?

pawn Код:
if(!(6 <= strlen(inputtext) <= 20))
{
    ShowPlayerDialog(playerid,REGISTRACIJA,DIALOG_STYLE_PASSWORD,"{FF0000}                 Registracija","{FF0000}_______________________________\n\n      Molim unesite zeljenu lozinku:\n_______________________________","Registriraj","Odustani");
    SendClientMessage(playerid,CRVENA,"Lozinka moћe imati najmanje 6 a najviљse 20 znakova!");
}
Quote:

Anyway how do you kick a player if he enters the password 3 times wrong?

Create a variable for the player, might as well be a PVar, which stores the amount of times he/she has entered a wrong password. Something like this:
pawn Код:
// in your Login(playerid, password[]) function:
// if the password is wrong, I don't know how you check it.
new pWarnings = GetPVarInt(playerid, "wrongPasswordsEntered") + 1;
if(pWarnings == 3)
{
    // kick the player
    return 1;
}
SetPVarInt(playerid, "wrongPasswordsEntered", pWarnings); // increase the value

// if the player logs in properly
DeletePVar(playerid, "wrongPasswordsEntered"); // don't keep the variable around in the memory
Reply
#6

I added all you said..

pawn Код:
enum PInfo
{
    Adminlevel,
    Loginf,
    Org
}
Under OnPlayerConnect

pawn Код:
if(Loginf == 3)
    {
        Kick(playerid);
        return 1;
    }
Under login
pawn Код:
if(dialogid==LOGIRANJE)
    {
        if(response==0)
        {
            ShowPlayerDialog(playerid,1,DIALOG_STYLE_MSGBOX,"{FF0000}                  GREЉKA","{FF0000}_______________________________\n\n      Odustali ste od logiranja pa\n\n           ste izbaceni  sa servera!\n\n_______________________________","Izadi","");
            for(new i = 0; i < 50; i++) SendClientMessageToAll(BIJELA," ");
            Kick(playerid);
            return 1;
        }
        if(response==1)
        {
            if(!strlen(inputtext))
            {
                new Loginf = GetPVarInt(playerid, "Loginf") + 1;
                SetPVarInt(playerid, "Loginf", Loginf);
                for(new i = 0; i < 50; i++) SendClientMessageToAll(BIJELA," ");
                ShowPlayerDialog(playerid,LOGIRANJE,DIALOG_STYLE_PASSWORD,"{FF0000}                  PRIJAVA","{00FF00}_______________________________\n\n         Vaљ Acount je pronaden!\n\n      Molimo unesite vaљu lozinku:\n_______________________________","Logiraj","Odustani");
                SendClientMessage(playerid,CRVENA,"Unjeli ste pogreљnu lozinku!");
            }
            else
            {
                Login(playerid,inputtext); //login
                return 1;
            }
        }
    }
Stock login
pawn Код:
stock Login(playerid,key[])
{
    new datoteka[64];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(datoteka,sizeof(datoteka),"/korisnici/%s.txt",name);
    if(!strcmp(key,dini_Get(datoteka,"Lozinka"),true))
    {
        UcitavanjeAcc(playerid);
        SendClientMessage(playerid,CRVENA,"Ulogirani ste");
        return 1;
    }
    else
    {
        SendClientMessage(playerid,CRVENA,"Unjeli ste pogreљnu lozinku!Pokuљajte ponovo!");
        ShowPlayerDialog(playerid,LOGIRANJE,DIALOG_STYLE_PASSWORD,"{FF0000}                  PRIJAVA","{00FF00}_______________________________\n\n         Vaљ Acount je pronaden!\n\n      Molimo unesite vaљu lozinku:\n_______________________________","Logiraj","Odustani");
        return 1;
    }
}
Loading account
pawn Код:
stock UcitavanjeAcc(playerid)
{
    new datoteka[64];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(datoteka,sizeof(datoteka),"/korisnici/%s.txt",name);
    SetPlayerScore(playerid,dini_Int(datoteka,"Level"));
    GivePlayerMoney(playerid,dini_Int(datoteka,"Novac"));
    IgracInfo[playerid][Adminlevel]=dini_Int(datoteka,"Adminlevel");
    IgracInfo[playerid][Org]=dini_Int(datoteka,"Org");
    IgracInfo[playerid][LoginF]=dini_Int(datoteka,"Loginf");
    return 1;
}
Saving acc
pawn Код:
stock SpremanjeAcc(playerid)
{
    new datoteka[64];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(datoteka,sizeof(datoteka),"/korisnici/%s.txt",name);
    dini_IntSet(datoteka,"Level",GetPlayerScore(playerid));
    dini_IntSet(datoteka,"Novac",GetPlayerMoney(playerid));
    dini_IntSet(datoteka,"Adminlevel",IgracInfo[playerid][Adminlevel]);
    dini_IntSet(datoteka,"Org",IgracInfo[playerid][Org]);
    dini_IntSet(datoteka,"Loginf",IgracInfo[playerid][Loginf]);
    return 1;
}
Reset variable
pawn Код:
stock ResetVar(playerid)
{
    IgracInfo[playerid][Adminlevel]=0;
    IgracInfo[playerid][Org]=0;
    IgracInfo[playerid][Loginf]=0;
    return 1;
}
And it gives me the folowing warnings;

gamemode1.pwn(92) : warning 213: tag mismatch
gamemode1.pwn(92) : warning 205: redundant code: constant expression is zero

pawn Код:
if(Loginf == 3) //this line
    {
    Kick(playerid);
    return 1;
    }
gamemode1.pwn(299) : warning 219: local variable "Loginf" shadows a variable at a preceding level
gamemode1.pwn(300) : warning 213: tag mismatch
gamemode1.pwn(299) : warning 204: symbol is assigned a value that is never used: "Loginf"

pawn Код:
if(dialogid==LOGIRANJE)
    {
        if(response==0)
        {
            ShowPlayerDialog(playerid,1,DIALOG_STYLE_MSGBOX,"{FF0000}                  GREЉKA","{FF0000}_______________________________\n\n      Odustali ste od logiranja pa\n\n           ste izbaceni  sa servera!\n\n_______________________________","Izadi","");
            for(new i = 0; i < 50; i++) SendClientMessageToAll(BIJELA," ");
            Kick(playerid);
            return 1;
        }
        if(response==1)
        {
            if(!strlen(inputtext))
            {
                new Loginf = GetPVarInt(playerid, "Loginf") + 1; // line 299
                SetPVarInt(playerid, "Loginf", Loginf); //line 300
                for(new i = 0; i < 50; i++) SendClientMessageToAll(BIJELA," ");
                ShowPlayerDialog(playerid,LOGIRANJE,DIALOG_STYLE_PASSWORD,"{FF0000}                  PRIJAVA","{00FF00}_______________________________\n\n         Vaљ Acount je pronaden!\n\n      Molimo unesite vaљu lozinku:\n_______________________________","Logiraj","Odustani");
                SendClientMessage(playerid,CRVENA,"Unjeli ste pogreљnu lozinku!");
            }
            else
            {
                Login(playerid,inputtext); //login
                return 1;
            }
        }
    }
Reply
#7

I fixed all the warnings and errors.
It saves Loginf wen i exit the server.
How do i now check the "Loginf" when the player enters the server and kick him?

EDIT: here's the solution

pawn Код:
IgracInfo[playerid][Loginf] += 1;
        if(IgracInfo[playerid][Loginf] == 5)
        {
            Kick(playerid);
            SendClientMessage(playerid,CRVENA,"Unjeli ste pogreљnu lozinku previљe puta i izbaceni ste sa servera!");
        }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)