SA-MP Forums Archive
MySQL problem - Custom code will always login (even if account does not exist) - 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: MySQL problem - Custom code will always login (even if account does not exist) (/showthread.php?tid=494808)



MySQL problem - Custom code will always login (even if account does not exist) - Private200 - 14.02.2014

So, I am having a problem with my accounts. I badly deleted a code I had that could load the accounts and I tried to create a custom code in order to open them.


Well, I do not know what the problem is, but it will always login even if there's no account registered.

This is the code I am using:

pawn Код:
new userquery[256];
    format(userquery, sizeof(userquery), "SELECT * FROM Users WHERE Name = '%s'", PlayerName);
    mysql_query(MySQLConnection, userquery);
    mysql_store_result(MySQLConnection);
    new rows = mysql_num_rows(MySQLConnection);
    if(!rows)
    {
        ShowPlayerDialog(playerid, DIALOG_TYPE_LOGIN, DIALOG_STYLE_PASSWORD, "Server Login", "Server Login:\n\nThe account with the name you joined is already registered!\nType your password below to retrieve your stats!", "Login", "");
    }
    if(rows == 1)
    {
        ShowPlayerDialog(playerid, DIALOG_TYPE_REGISTER, DIALOG_STYLE_INPUT, "Server Register", "Server Register:\n\nThe account with the name you joined is not yet registered!\nType your password below to save your stats!\n\nNote: Do not press ESC or you will be kicked.", "Register", "Kick");
    }
    mysql_free_result(MySQLConnection);
Thanks...


Re: MySQL problem - Custom code will always login (even if account does not exist) - CuervO - 14.02.2014

Are you sure you've used the correct functions? What version of SQL are you using? For anything above R7 the data is stored in the cache.


Re: MySQL problem - Custom code will always login (even if account does not exist) - Private200 - 14.02.2014

Using R7


Re: MySQL problem - Custom code will always login (even if account does not exist) - CuervO - 14.02.2014

R7 only supports cached data & threaded queries.

https://sampforum.blast.hk/showthread.php?tid=337810


Re: MySQL problem - Custom code will always login (even if account does not exist) - Private200 - 14.02.2014

I've got this also:

pawn Код:
new escapedPlayerName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
        mysql_real_escape_string(PlayerName, escapedPlayerName);
        format(string, sizeof(string), "SELECT * FROM Users WHERE Name = '%s'", escapedPlayerName);
        mysql_query(string, THREAD_USER_LOOKUP, playerid, MySQLConnection);
and THREAD_USER_LOOKUP responses to this:

pawn Код:
case THREAD_USER_LOOKUP:
        {
            mysql_store_result(connectionHandle);
            if(mysql_num_rows(connectionHandle) > 0)
            {
                new Return[256];
                mysql_retrieve_row();

                cache_get_field_content(0, "VIP", Return);
                PlayerInfo[extraid][pTempVIP] = strval(Return);
               
                cache_get_field_content(0, "Admin", Return);
                PlayerInfo[extraid][pTempAdmin] = strval(Return);

                cache_get_field_content(0, "Password", Return);
                format(PlayerInfo[extraid][pPassword], 256, Return);

                mysql_free_result(connectionHandle);

                ShowPlayerDialog(extraid, DIALOG_TYPE_LOGIN, DIALOG_STYLE_PASSWORD, "Server Login", "Server Login:\n\nThe account with the name you joined is already registered!\nType your password below to retrieve your stats!", "Login", "");
            }
            else
            {
                ShowPlayerDialog(extraid, DIALOG_TYPE_REGISTER, DIALOG_STYLE_INPUT, "Server Register", "Server Register:\n\nThe account with the name you joined is not yet registered!\nType your password below to save your stats!\n\nNote: Do not press ESC or you will be kicked.", "Register", "Kick");
            }
        }
But it wont show anything at all...


Re: MySQL problem - Custom code will always login (even if account does not exist) - ColeMiner - 14.02.2014

Why are you writing your own user system instead of downloading a secure and well tested one?


Re: MySQL problem - Custom code will always login (even if account does not exist) - Djole1337 - 14.02.2014

Quote:
Originally Posted by Private200
Посмотреть сообщение
So, I am having a problem with my accounts. I badly deleted a code I had that could load the accounts and I tried to create a custom code in order to open them.


Well, I do not know what the problem is, but it will always login even if there's no account registered.

This is the code I am using:

pawn Код:
new userquery[256];
    format(userquery, sizeof(userquery), "SELECT * FROM Users WHERE Name = '%s'", PlayerName);
    mysql_query(MySQLConnection, userquery);
    mysql_store_result(MySQLConnection);
    new rows = mysql_num_rows(MySQLConnection);
    if(!rows)
    {
        ShowPlayerDialog(playerid, DIALOG_TYPE_LOGIN, DIALOG_STYLE_PASSWORD, "Server Login", "Server Login:\n\nThe account with the name you joined is already registered!\nType your password below to retrieve your stats!", "Login", "");
    }
    if(rows == 1)
    {
        ShowPlayerDialog(playerid, DIALOG_TYPE_REGISTER, DIALOG_STYLE_INPUT, "Server Register", "Server Register:\n\nThe account with the name you joined is not yet registered!\nType your password below to save your stats!\n\nNote: Do not press ESC or you will be kicked.", "Register", "Kick");
    }
    mysql_free_result(MySQLConnection);
Thanks...
wait what...
if no rows -> login

it should be
if (rows) // login dialog
else // register dialog

also don't fetch the whole table... you can do something like
Код:
select count(*) from `Users` where `Account` = '%s' limit 0,1;



Re: MySQL problem - Custom code will always login (even if account does not exist) - CuervO - 15.02.2014

Quote:
Originally Posted by Djole1337
Посмотреть сообщение
wait what...
if no rows -> login

it should be
if (rows) // login dialog
else // register dialog

also don't fetch the whole table... you can do something like
Код:
select count(*) from `Users` where `Account` = '%s' limit 0,1;
That, also, the query will fail because unthreaded queries are not supported by R7. As I already said you need to thread it into a function and use the cache data.