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

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...
Reply
#2

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.
Reply
#3

Using R7
Reply
#4

R7 only supports cached data & threaded queries.

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

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...
Reply
#6

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

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;
Reply
#8

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)