Login CMD
#1

I'm having trouble with my login CMD. Whenever a player logs into an account and he types /login [somerandomshithere], he's logged in, even if the password is incorrect. What's the problem here?

My full login CMD:

pawn Код:
CMD:login(playerid, params[])
{
    new file[32], pass[40];
    format(file,sizeof(file),"/Users2/%s.ini", GetName(playerid));
    if(sscanf(params,"s[40]",pass)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /login [password]");
    if(fexist(file))
    {
        if(IsLogged[playerid] == 0)
        {
            if(PlayerInfo[playerid][pPass] == strval(pass))
            {
                SendClientMessage(playerid, COLOR_ORANGE, "You've succesfully logged in. Enjoy your stay!");
                IsLogged[playerid] = 1;
                TogglePlayerControllable(playerid, true);
            }
            else
            {
                SendClientMessage(playerid, COLOR_LIGHTRED, "Wrong password! Please try again.");
                pTurns[playerid]++;
               
                if(pTurns[playerid] == 1) { SendClientMessage(playerid, COLOR_RED, "You can try 2 more times."); }
                else if(pTurns[playerid] == 2) { SendClientMessage(playerid, COLOR_RED, "You can try 1 more time."); }
                else if(pTurns[playerid] == 3)
                {
                    new str[150];
                    format(str,sizeof(str),"SERVER: %s has been kicked by Security Guard, reason: Wrong password.", GetName(playerid));
                    SendClientMessageToAll(COLOR_LIGHTRED, str);
                    pTurns[playerid] = 0;
                    Kick(playerid);
                }
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_GRAD2, "You're already logged in.");
        }
    }
    return 1;
}
Code that should check if the pass equals to the players pass:

pawn Код:
if(PlayerInfo[playerid][pPass] == strval(pass))
            {
                SendClientMessage(playerid, COLOR_ORANGE, "You've succesfully logged in. Enjoy your stay!");
                IsLogged[playerid] = 1;
                TogglePlayerControllable(playerid, true);
            }
Anybody know how to fix this issue?
Reply
#2

Nonononono. Use strcmp for string comparing:
pawn Код:
if( !strcmp( PlayerInfo[ playerid ][ pPass ],  pass ))
You should also consider using a hash (For example Whirlpool) as your password storing is extremely unsafe.
Reply
#3

Oh alright. Thanks for your help, and I'll take a look at a hash. I know it's a simple login/register system, but I'm trying to script on my own at the moment and this was the easiest way . Anyway, thanks a lot!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)