[SOLVED]OnPlayerLogin
#1

This is my code:

pawn Код:
public OnPlayerLogin(playerid, password[])
{
  new name[MAX_PLAYER_NAME], str[128], string[MAX_STRING];
  GetPlayerName(playerid, name, sizeof name);
    format(str, sizeof str, "/CoDS/Accounts/%s.account", name);
    string = dini_Get(str, "Password");
   
    if(strcmp(string, password, true))
    {
        SendClientMessage(playerid, COLOR_RED, "Incorrect Password.");
      return 1;
    }
    AccountInfo[playerid][AdminLevel] = dini_Int(str, "AdminLevel");
  AccountInfo[playerid][MWeap1] = dini_Int(str, "MeleeWeap1");
  AccountInfo[playerid][PWeap1] = dini_Int(str, "PrimaryWeap1");
  AccountInfo[playerid][SWeap1] = dini_Int(str, "SecondaryWeap1");
  AccountInfo[playerid][SPWeap1] = dini_Int(str, "SpecialWeap1");
  AccountInfo[playerid][MWeap2] = dini_Int(str, "MeleeWeap2");
  AccountInfo[playerid][PWeap2] = dini_Int(str, "PrimaryWeap2");
  AccountInfo[playerid][SWeap2] = dini_Int(str, "SecondaryWeap2");
  AccountInfo[playerid][SPWeap2] = dini_Int(str, "SpecialWeap2");
  AccountInfo[playerid][Rank] = dini_Int(str, "Rank");
  AccountInfo[playerid][Kills] = dini_Int(str, "Kills");
  AccountInfo[playerid][Deaths] = dini_Int(str, "Deaths");
  AccountInfo[playerid][RoundsWon] = dini_Int(str, "RoundsWon");
 
    SetPlayerScore(playerid, AccountInfo[playerid][RoundsWon]);
    SpawnPlayer(playerid);
    printf("%s has logged in", name);
    AccountInfo[playerid][Logged] = 1;
    if (AccountInfo[playerid][AdminLevel] > 0)
    {
        format(str, sizeof str, "You have successfully logged in as %s [Admin level %d]", name, AccountInfo[playerid][AdminLevel]);
        SendClientMessage(playerid, COLOR_YELLOW, str);
    }
    else
    {
      format(str, sizeof str, "You have successfully logged in as %s", name);
      SendClientMessage(playerid, COLOR_YELLOW, str);
    }
    return 1;
}
The problem is, you can log in with anything as the password. I've been playing around with it but I can't get it to work.

EDIT: You can log in with anything but the right password lol. Not quite sure how to make it the right way round.
Reply
#2

What encryption code did you use for registering?
If you used some sort of encryption like MD5 or Hash then when you check if he logged in it checks the exact thing he wrote.
If he types:

/login ilikecheez

It will check for the "ilikecheez" he wrote and return if its true or not.
I am not so sure but i think it will just check for "ilikecheez" and not the encrypted code.
So you better use DUDB too.


P.S Sorry for my English, i just woke up
Reply
#3

I'm using MD5. It's weird because say I registered with the password "hello" then when I login with "hello" it says incorrect password, but if I log in with anything else like "fbdshjfbfh" it would log me in. So the whole thing is round the wrong way.
Reply
#4

Hmm you tried doing like..

pawn Код:
public OnPlayerLogin(playerid, password[])
{
  new name[MAX_PLAYER_NAME], str[128], string[MAX_STRING];
  GetPlayerName(playerid, name, sizeof name);
    format(str, sizeof str, "/CoDS/Accounts/%s.account", name);
    string = dini_Get(str, "Password");
   
    if(strcmp(string, password, false))
    {
        SendClientMessage(playerid, COLOR_RED, "Incorrect Password.");
      return 1;
    }
    AccountInfo[playerid][AdminLevel] = dini_Int(str, "AdminLevel");
  AccountInfo[playerid][MWeap1] = dini_Int(str, "MeleeWeap1");
  AccountInfo[playerid][PWeap1] = dini_Int(str, "PrimaryWeap1");
  AccountInfo[playerid][SWeap1] = dini_Int(str, "SecondaryWeap1");
  AccountInfo[playerid][SPWeap1] = dini_Int(str, "SpecialWeap1");
  AccountInfo[playerid][MWeap2] = dini_Int(str, "MeleeWeap2");
  AccountInfo[playerid][PWeap2] = dini_Int(str, "PrimaryWeap2");
  AccountInfo[playerid][SWeap2] = dini_Int(str, "SecondaryWeap2");
  AccountInfo[playerid][SPWeap2] = dini_Int(str, "SpecialWeap2");
  AccountInfo[playerid][Rank] = dini_Int(str, "Rank");
  AccountInfo[playerid][Kills] = dini_Int(str, "Kills");
  AccountInfo[playerid][Deaths] = dini_Int(str, "Deaths");
  AccountInfo[playerid][RoundsWon] = dini_Int(str, "RoundsWon");
 
    SetPlayerScore(playerid, AccountInfo[playerid][RoundsWon]);
    SpawnPlayer(playerid);
    printf("%s has logged in", name);
    AccountInfo[playerid][Logged] = 1;
    if (AccountInfo[playerid][AdminLevel] > 0)
    {
        format(str, sizeof str, "You have successfully logged in as %s [Admin level %d]", name, AccountInfo[playerid][AdminLevel]);
        SendClientMessage(playerid, COLOR_YELLOW, str);
    }
    else
    {
      format(str, sizeof str, "You have successfully logged in as %s", name);
      SendClientMessage(playerid, COLOR_YELLOW, str);
    }
    return 1;
}
If this one doesn't work maybe just try doing everything you did with the password check like opposite
Reply
#5

That kind of works, but if you get the pass wrong like 2 times, it doesn't let you log in with the right password.
But if you enter the server and log in with the right password first, it works.
Reply
#6

Maybe try going the way around it, you said after 2 wrong passwords it doesn't let you log-in anymore?
Then try make some sort of protection like this, it checks how much times he failed to log-in, then kicks him after next try.

Add this on top

pawn Код:
new PWFails[MAX_PLAYERS];
pawn Код:
public OnPlayerLogin(playerid, password[])
{
  new name[MAX_PLAYER_NAME], str[128], string[MAX_STRING];
  GetPlayerName(playerid, name, sizeof name);
    format(str, sizeof str, "/CoDS/Accounts/%s.account", name);
    string = dini_Get(str, "Password");
   
    if(strcmp(string, password, false))
    {
        if (PWFails[playerid] < 2)
        {
        PWFails[playerid]++;
        SendClientMessage(playerid, COLOR_RED, "Incorrect Password.");
        }
        if (PWFails[playerid] == 2)
        {
        Kick(playerid);
        }
        return 1;
    }
    AccountInfo[playerid][AdminLevel] = dini_Int(str, "AdminLevel");
  AccountInfo[playerid][MWeap1] = dini_Int(str, "MeleeWeap1");
  AccountInfo[playerid][PWeap1] = dini_Int(str, "PrimaryWeap1");
  AccountInfo[playerid][SWeap1] = dini_Int(str, "SecondaryWeap1");
  AccountInfo[playerid][SPWeap1] = dini_Int(str, "SpecialWeap1");
  AccountInfo[playerid][MWeap2] = dini_Int(str, "MeleeWeap2");
  AccountInfo[playerid][PWeap2] = dini_Int(str, "PrimaryWeap2");
  AccountInfo[playerid][SWeap2] = dini_Int(str, "SecondaryWeap2");
  AccountInfo[playerid][SPWeap2] = dini_Int(str, "SpecialWeap2");
  AccountInfo[playerid][Rank] = dini_Int(str, "Rank");
  AccountInfo[playerid][Kills] = dini_Int(str, "Kills");
  AccountInfo[playerid][Deaths] = dini_Int(str, "Deaths");
  AccountInfo[playerid][RoundsWon] = dini_Int(str, "RoundsWon");
 
    SetPlayerScore(playerid, AccountInfo[playerid][RoundsWon]);
    SpawnPlayer(playerid);
    printf("%s has logged in", name);
    AccountInfo[playerid][Logged] = 1;
    if (AccountInfo[playerid][AdminLevel] > 0)
    {
        format(str, sizeof str, "You have successfully logged in as %s [Admin level %d]", name, AccountInfo[playerid][AdminLevel]);
        SendClientMessage(playerid, COLOR_YELLOW, str);
    }
    else
    {
      format(str, sizeof str, "You have successfully logged in as %s", name);
      SendClientMessage(playerid, COLOR_YELLOW, str);
    }
    return 1;
}
If you don't really like how it is made, maybe try this one, Untested.
pawn Код:
public OnPlayerLogin(playerid, password[])
{
  new name[MAX_PLAYER_NAME], str[128];
  GetPlayerName(playerid, name, sizeof name);
    format(str, sizeof str, "/CoDS/Accounts/%s.account", name);
   
    if(strcmp(dini_Get(str, "Password"), password, false))
    {
        SendClientMessage(playerid, COLOR_RED, "Incorrect Password.");
      return 1;
    }
    AccountInfo[playerid][AdminLevel] = dini_Int(str, "AdminLevel");
  AccountInfo[playerid][MWeap1] = dini_Int(str, "MeleeWeap1");
  AccountInfo[playerid][PWeap1] = dini_Int(str, "PrimaryWeap1");
  AccountInfo[playerid][SWeap1] = dini_Int(str, "SecondaryWeap1");
  AccountInfo[playerid][SPWeap1] = dini_Int(str, "SpecialWeap1");
  AccountInfo[playerid][MWeap2] = dini_Int(str, "MeleeWeap2");
  AccountInfo[playerid][PWeap2] = dini_Int(str, "PrimaryWeap2");
  AccountInfo[playerid][SWeap2] = dini_Int(str, "SecondaryWeap2");
  AccountInfo[playerid][SPWeap2] = dini_Int(str, "SpecialWeap2");
  AccountInfo[playerid][Rank] = dini_Int(str, "Rank");
  AccountInfo[playerid][Kills] = dini_Int(str, "Kills");
  AccountInfo[playerid][Deaths] = dini_Int(str, "Deaths");
  AccountInfo[playerid][RoundsWon] = dini_Int(str, "RoundsWon");
 
    SetPlayerScore(playerid, AccountInfo[playerid][RoundsWon]);
    SpawnPlayer(playerid);
    printf("%s has logged in", name);
    AccountInfo[playerid][Logged] = 1;
    if (AccountInfo[playerid][AdminLevel] > 0)
    {
        format(str, sizeof str, "You have successfully logged in as %s [Admin level %d]", name, AccountInfo[playerid][AdminLevel]);
        SendClientMessage(playerid, COLOR_YELLOW, str);
    }
    else
    {
      format(str, sizeof str, "You have successfully logged in as %s", name);
      SendClientMessage(playerid, COLOR_YELLOW, str);
    }
    return 1;
}
What i did is just removed the string thing and added the dini_get in the login check, since your kinda using it once here.
Maybe it is all about speed, so try it with this one if you don't like the one i did above.

If all of this doesn't work, try follow and take some stuff from Boogeyman's tutorial

http://forum.sa-mp.com/index.php?topic=69810.0
Reply
#7

That last one seems to have worked, cheers man.
Reply
#8

Quote:
Originally Posted by Gappy
That last one seems to have worked, cheers man.
No problem, if you need anything else send me a forum PM.
Reply
#9

Ok, I found the exact problem now. If you try login with the password being 1 character, then it wont let you log in.
So if my pass was "hello" and I type /login h then /login hello, it will say incorrect password.

So how can I make it so you can't type a password less than 2 characters?
Reply
#10

I think this should be right.
pawn Код:
public OnPlayerLogin(playerid, password[])
{
  new name[MAX_PLAYER_NAME], str[128];
  GetPlayerName(playerid, name, sizeof name);
    format(str, sizeof str, "/CoDS/Accounts/%s.account", name);
    if (strlen(password) < 2)
    {
      SendClientMessage(playerid, COLOR_RED, "Password can't be less than 1 Character");
      return 1;
    }
    if(strcmp(dini_Get(str, "Password"), password, false))
    {
        SendClientMessage(playerid, COLOR_RED, "Incorrect Password.");
      return 1;
    }
    AccountInfo[playerid][AdminLevel] = dini_Int(str, "AdminLevel");
  AccountInfo[playerid][MWeap1] = dini_Int(str, "MeleeWeap1");
  AccountInfo[playerid][PWeap1] = dini_Int(str, "PrimaryWeap1");
  AccountInfo[playerid][SWeap1] = dini_Int(str, "SecondaryWeap1");
  AccountInfo[playerid][SPWeap1] = dini_Int(str, "SpecialWeap1");
  AccountInfo[playerid][MWeap2] = dini_Int(str, "MeleeWeap2");
  AccountInfo[playerid][PWeap2] = dini_Int(str, "PrimaryWeap2");
  AccountInfo[playerid][SWeap2] = dini_Int(str, "SecondaryWeap2");
  AccountInfo[playerid][SPWeap2] = dini_Int(str, "SpecialWeap2");
  AccountInfo[playerid][Rank] = dini_Int(str, "Rank");
  AccountInfo[playerid][Kills] = dini_Int(str, "Kills");
  AccountInfo[playerid][Deaths] = dini_Int(str, "Deaths");
  AccountInfo[playerid][RoundsWon] = dini_Int(str, "RoundsWon");
 
    SetPlayerScore(playerid, AccountInfo[playerid][RoundsWon]);
    SpawnPlayer(playerid);
    printf("%s has logged in", name);
    AccountInfo[playerid][Logged] = 1;
    if (AccountInfo[playerid][AdminLevel] > 0)
    {
        format(str, sizeof str, "You have successfully logged in as %s [Admin level %d]", name, AccountInfo[playerid][AdminLevel]);
        SendClientMessage(playerid, COLOR_YELLOW, str);
    }
    else
    {
      format(str, sizeof str, "You have successfully logged in as %s", name);
      SendClientMessage(playerid, COLOR_YELLOW, str);
    }
    return 1;
}

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)