Login CMD - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Login CMD (
/showthread.php?tid=413466)
Login CMD -
Da_Noob - 05.02.2013
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?
Re: Login CMD -
LarzI - 05.02.2013
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.
Re: Login CMD -
Da_Noob - 05.02.2013
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!