SA-MP Forums Archive
[MySQL]: Somethings wrong with my login command? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [MySQL]: Somethings wrong with my login command? (/showthread.php?tid=152950)



[MySQL]: Somethings wrong with my login command? - Niixie - 06.06.2010

Hey, Heres my login command

pawn Код:
CMD:login(playerid, params[])
{
    new LogPass[24], pname[MAX_PLAYER_NAME], str[128];
    if(sscanf(params, "s", LogPass)) return SENDMSG(playerid, COLOR_GREENLIGHT, "[WR Usage]: /login [Password]");
    else if (strlen(LogPass) > 24) return ERRORMSG(playerid, "[WR Server]: The password is you typed is too long, try again");
    else if(IsLogged[playerid] == 1) return ERRORMSG(playerid, "[WR Server]: You're already logged in!");
    else
    {
      GetPlayerName(playerid, pname, sizeof(pname));
      format(query, sizeof(query), "SELECT * FROM users WHERE username = '%s'", PlayerName);
      mysql_query(query);
      mysql_store_result();
        if(mysql_num_rows() != 0)
        {
          format(query, sizeof(query), "SELECT password FROM users WHERE username = '%s'", PlayerName);
            mysql_query(query);
            mysql_store_result();
            if(strlen(query) == strlen(LogPass)) // Change to != if its all wrong on login
            {
        LoadStats(playerid);
            }
            else
            {
              format(str, sizeof(str), "logpass: %s, query: %s", strval(LogPass), strval(query));
                ERRORMSG(playerid, "[WR Server]: Login failed, try again");
            }
        }
        else
        {
            SENDMSG(playerid, COLOR_GREENLIGHT, "[WR Server]: This username is not found in the database, please use /register");
        }
    }
    return 1;
}
Theres something wrong with it, when i register (my register command works fine) and after i login it says its the wrong pass?
I cant see whats wrong, and im new to mysql so i dont know all the callbacks yet.


Re: [MySQL]: Somethings wrong with my login command? - [Ger]Little_Grandpa - 06.06.2010

Код:
mysql_store_result();
mysql_fetch_field("password",query);
if(strlen........



Re: [MySQL]: Somethings wrong with my login command? - Niixie - 06.06.2010

like this?

pawn Код:
format(query, sizeof(query), "SELECT password FROM users WHERE username = '%s'", PlayerName);
            mysql_query(query);
            mysql_store_result();
            mysql_fetch_field("password",query);
            if(strlen(query) == strlen(LogPass)) // Change to != if its all wrong on login
            {
        LoadStats(playerid);
            }
What does it do, can you explain for me?


Re: [MySQL]: Somethings wrong with my login command? - [Ger]Little_Grandpa - 06.06.2010

yes^^
it fetches the query-result...


Re: [MySQL]: Somethings wrong with my login command? - Niixie - 06.06.2010

It give me error:
Код:
error 035: argument type mismatch (argument 1)
the new line is the error line


Re: [MySQL]: Somethings wrong with my login command? - Sergei - 06.06.2010

Lol what fail.

You check if password's length is same as length of query. Use some sense at least.


Re: [MySQL]: Somethings wrong with my login command? - Niixie - 06.06.2010

it should be strval?