Login Problems
#1

Hey guys, i am the man with the most problems, lol.

Anyways this time, my problem is with login, ofc i fix register then login decides to fuck up -.-.

My original login code was:

pawn Код:
if (dialogid == 2)
    {
    new string[128], escpass[100], escname[MAX_PLAYER_NAME];
    //GetPlayerName(playerid, Name, sizeof(Name));
    mysql_real_escape_string(inputtext, escpass);
    mysql_real_escape_string(UserStats[playerid][Name], escname);
    GetPlayerName(playerid, escname, MAX_PLAYER_NAME);
    format(string,sizeof(string),"INSERT INTO `Users` (`Name`, `Password`) VALUES ('%s', '%s')",escname, escpass);
    mysql_query(string);

    if(!mysql_num_rows())
        return SendClientMessage(playerid, COLOR_RED, "[ACCOUNT] Incorrect password!");

    new row[128];
    new field[7][32]; // [4] = Amount of fields, [24] = Max length of the bigest field.

    mysql_fetch_row_format(row, "|");
    explode(row, field, "|");
    mysql_free_result();

    // The field starts here with 1, because the field 'Name' = 0, and we already have the name in a variable.
    format(UserStats[playerid][Password], 32, "%s", field[1]);
    UserStats[playerid][Admin] = strval(field[2]);
    UserStats[playerid][Money] = strval(field[3]);
    UserStats[playerid][ppos_x] = strval(field[4]);
    UserStats[playerid][ppos_y] = strval(field[5]);
    UserStats[playerid][ppos_z] = strval(field[6]);

    GivePlayerCash(playerid, UserStats[playerid][Money]);
    SetPlayerPos(playerid, UserStats[playerid][ppos_x], UserStats[playerid][ppos_y], UserStats[playerid][ppos_z]);
    }
Yes, i noticed is says insert, so i asked a bud and he told me it was wrong, then i noticed i use insert instead of select, so he gave me this edit:

pawn Код:
if (dialogid == 2)
    {
    new string[128], escpass[100], escname[MAX_PLAYER_NAME];
    //GetPlayerName(playerid, Name, sizeof(Name));
    mysql_real_escape_string(inputtext, escpass);
    mysql_real_escape_string(UserStats[playerid][Name], escname);
    GetPlayerName(playerid, escname, MAX_PLAYER_NAME);
    //format(string,sizeof(string),"INSERT INTO `Users` (`Name`, `Password`) VALUES ('%s', '%s')",escname, escpass);
    //mysql_query(string);

    //if(!mysql_num_rows())
    //  return SendClientMessage(playerid, COLOR_RED, "[ACCOUNT] Incorrect password!");

    new row[128];
    new field[7][32]; // [4] = Amount of fields, [24] = Max length of the bigest field.

    mysql_fetch_row_format(row, "|");
    explode(row, field, "|");
    mysql_free_result();

    if(strcmp(inputtext,field[1], true) == 0)
        {

    // The field starts here with 1, because the field 'Name' = 0, and we already have the name in a variable.
        format(UserStats[playerid][Password], 32, "%s", field[1]);
        UserStats[playerid][Admin] = strval(field[2]);
        UserStats[playerid][Money] = strval(field[3]);
        UserStats[playerid][ppos_x] = strval(field[4]);
        UserStats[playerid][ppos_y] = strval(field[5]);
        UserStats[playerid][ppos_z] = strval(field[6]);

        GivePlayerCash(playerid, UserStats[playerid][Money]);
        SetPlayerPos(playerid, UserStats[playerid][ppos_x], UserStats[playerid][ppos_y], UserStats[playerid][ppos_z]);
        }
    }
Yesh, it solved one of my problems, but now my problem is, if you use wrong password, you still can login, if you put no password, you can still login. Help me please .

Thanks in advance,


-Anthony
Reply
#2

Didn't use response, and fixed the strcmp line.

Try now.

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 2)
    {
        if(response)
        {
            new string[128], escpass[100], escname[MAX_PLAYER_NAME];
            //GetPlayerName(playerid, Name, sizeof(Name));
            mysql_real_escape_string(inputtext, escpass);
            mysql_real_escape_string(UserStats[playerid][Name], escname);
            GetPlayerName(playerid, escname, MAX_PLAYER_NAME);
            //format(string,sizeof(string),"INSERT INTO `Users` (`Name`, `Password`) VALUES ('%s', '%s')",escname, escpass);
            //mysql_query(string);

            //if(!mysql_num_rows())
            //  return SendClientMessage(playerid, COLOR_RED, "[ACCOUNT] Incorrect password!");

            new row[128];
            new field[7][32]; // [4] = Amount of fields, [24] = Max length of the bigest field.

            mysql_fetch_row_format(row, "|");
            explode(row, field, "|");
            mysql_free_result();

            if(!strlen(inputtext))
            {
                // ShowPlayerDialog for register
                return 1;
            }

            if(strcmp(inputtext, UserStats[playerid][Password], false) == 0)
            {
                // The field starts here with 1, because the field 'Name' = 0, and we already have the name in a variable.
                format(UserStats[playerid][Password], 32, "%s", field[1]);
                UserStats[playerid][Admin] = strval(field[2]);
                UserStats[playerid][Money] = strval(field[3]);
                UserStats[playerid][ppos_x] = strval(field[4]);
                UserStats[playerid][ppos_y] = strval(field[5]);
                UserStats[playerid][ppos_z] = strval(field[6]);
                GivePlayerCash(playerid, UserStats[playerid][Money]);
                SetPlayerPos(playerid, UserStats[playerid][ppos_x], UserStats[playerid][ppos_y], UserStats[playerid][ppos_z]);
            }
        }
    }
    return 1;
}
Reply
#3

still lets me login with any password, wrong or not
Reply
#4

Just a minor modification; does it work?

pawn Код:
if(strcmp(inputtext, escpass, false) == 0)
            {
                // The field starts here with 1, because the field 'Name' = 0, and we already have the name in a variable.
                format(UserStats[playerid][Password], 32, "%s", field[1]);
                UserStats[playerid][Admin] = strval(field[2]);
                UserStats[playerid][Money] = strval(field[3]);
                UserStats[playerid][ppos_x] = strval(field[4]);
                UserStats[playerid][ppos_y] = strval(field[5]);
                UserStats[playerid][ppos_z] = strval(field[6]);
                GivePlayerCash(playerid, UserStats[playerid][Money]);
                SetPlayerPos(playerid, UserStats[playerid][ppos_x], UserStats[playerid][ppos_y], UserStats[playerid][ppos_z]);
            }
Reply
#5

Perform a SELECT query with the user credentials:

pawn Код:
format(string,sizeof(string),"SELECT NULL FROM Users WHERE Name = '%s' AND Password = '%s'",escname, escpass);
    mysql_query(string);

    if(!mysql_num_rows()) return SendClientMessage(playerid, COLOR_RED, "[ACCOUNT] Incorrect password!");
You should be using threaded queries.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)