Login system error?
#1

Well i created a login / register system, not when i register, its fine, but one i' relog then it says invalid password, Any ideas?

--[My Code]--

Login & Reg CMDS
pawn Код:
if (strcmp(cmd, "/login", true) ==0 )
    {
      if(IsPlayerConnected(playerid))
      {
        new tmppass[64];
            if(gPlayerLogged[playerid] == 1)
            {
                SendClientMessage(playerid, COLOR_GREY, "..:[SERVER]: You are already logged in.");
                return 1;
            }
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GREY, "..:[SERVER]: /login [password]");
                return 1;
            }
            strmid(tmppass, tmp, 0, strlen(cmdtext), 255);
            Encrypt(tmppass);
            OnPlayerLogin(playerid,tmppass);
        }
        return 1;
    }
    if (strcmp(cmd, "/register", true)==0)
    {
        new string[265];
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_GREY, "..:[SERVER]: /register [password]");
            return 1;
        }
        if (gPlayerAccount[playerid] == 1)
        {
            SendClientMessage(playerid, COLOR_GREY, "..:[SERVER]: That name is already registered");
            return 1;
        }

        strmid(PlayerInfo[playerid][pPassword], tmp, 0, strlen(cmdtext), 255);
        Encrypt(PlayerInfo[playerid][pPassword]);
        GetPlayerName(playerid, playername, sizeof(playername));
        format(string, sizeof(string), "%s.ini", playername);
        new File: file = fopen(string, io_read);
        if (file)
        {
            SendClientMessage(playerid, COLOR_GREY, "..:[SERVER]: That name is already registered");
            fclose(file);
            return 1;
        }
        new File:hFile;
        hFile = fopen(string, io_append);
        new var[32];//
    format(var, 32, "Pass = %s\r\n", PlayerInfo[playerid][pPassword]);fwrite(hFile, var);
    format(var, 32, "Kills = %d\r\n",PlayerInfo[playerid][pKills]);fwrite(hFile, var);
    format(var, 32, "Deaths = %d\r\n",PlayerInfo[playerid][pDeaths]);fwrite(hFile, var);
    format(var, 32, "pAdminLvl = %s\r\n",PlayerInfo[playerid][pAdminLvl]);fwrite(hFile, var);
    format(var, 32, "IP Address = %s\r\n",PlayerInfo[playerid][pIP]);fwrite(hFile, var);
    format(var, 32, "Muted = %s\r\n",PlayerInfo[playerid][pMute]);fwrite(hFile, var);
    format(var, 32, "Warns = %s\r\n",PlayerInfo[playerid][pWarns]);fwrite(hFile, var);
    PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
    format(var, 32, "Money = %d\r\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
        fclose(hFile);
        SendClientMessage(playerid, COLOR_WHITE, "..:[SERVER]: Succesfully Registered!");
        SendClientMessage(playerid, COLOR_WHITE, "..:[SERVER]: Next time you connect, type /login <password> to log in.");
        OnPlayerLogin(playerid,PlayerInfo[playerid][pPassword]);
        return 1;
    }
Public Login / Register

pawn Код:
public OnPlayerLogin(playerid,const string[])
{
  new pname2[MAX_PLAYER_NAME];
    new pname3[MAX_PLAYER_NAME];
    new string2[64];
    new string3[128];
    GetPlayerName(playerid, pname2, sizeof(pname2));
    format(string2, sizeof(string2), "%s.ini", pname2);
    new File: UserFile = fopen(string2, io_read);

    if (UserFile)
    {
        new valtmp[128];
        fread(UserFile, valtmp);strmid(PlayerInfo[playerid][pPassword], valtmp, 0, strlen(valtmp)-1, 255);

        if ((strcmp(PlayerInfo[playerid][pPassword], string, true, strlen(valtmp)-1) == 0))
        {
            new key[128],val[128];
            new Data[128];
            while(fread(UserFile,Data,sizeof(Data)))
            {
                key = ini_GetKey(Data);
        if( strcmp( key , "Kills" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pKills] = strval( val ); }
        if( strcmp( key , "Deaths" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pDeaths] = strval( val ); }
        if( strcmp( key , "AdminLvl" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pAdminLvl] = strval( val ); }
        if( strcmp( key , "Muted" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pMute] = strval( val ); }
        if( strcmp( key , "IP" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pIP] = strval( val ); }
        if( strcmp( key , "Warns" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pWarns] = strval( val ); }
        if( strcmp( key , "Money" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pCash] = strval( val ); }
        GivePlayerMoney(playerid,PlayerInfo[playerid][pCash]);
            }
            fclose(UserFile);
            gPlayerLogged[playerid] = 1;
            gPlayerAccount[playerid] = 1;
          new kills = PlayerInfo[playerid][pKills];
      SetPlayerScore(playerid, kills);
            GetPlayerName(playerid, pname3, sizeof(pname3));
            format(string3, sizeof(string3), "..:[SERVER]: Welcome %s, Sucessfully Authed!", pname3);
            SendClientMessage(playerid, COLOR_WHITE,string3);
        }
        else
        {
            SendClientMessage(playerid, COLOR_GREY, "..:[SERVER]: Password does not match your name");
            fclose(UserFile);
        }
    }
    return 1;
}
Any Ideas? Thanks,

-Mike.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)