SQL Query doesn't grab the right info.
#1

As the topic says... This code tells the player it's wrong password. Wether it's wrong or right. And kicks them. Why?

pawn Код:
stock PlayerLogin(playerid, password)
{
    new str[128];
    format(str, sizeof(str),"SELECT * FROM users WHERE username = '%s' AND password = md5('%s')",pName(playerid),password);
    mysql_query(str);
    mysql_store_result();
    if(!mysql_num_rows())
    {
        SendInfoMessage(playerid,"Wrong {a9c4e4}password{ffffff}! Kicked due to security reasons!");
        Kick(playerid);
        mysql_free_result();
        return 1;
    }
    else
    {
        SendInfoMessage(playerid,"Successfully logged in. Welcome back!");
        mysql_free_result();
        return 1;
    }
}
Reply
#2

Did you correctly type in the password with upper/lowercase in mind? The MD5 hash of "test" is not the same as the MD5 hash of "TeSt".
Reply
#3

pawn Код:
stock PlayerLogin(playerid, const password[])
or if your password is a number you must convert it to string
Reply
#4

I have typed it correct. I've even registered 2 account and check the password hashes manually. they are identical. It's not numbers. it's only characters.
Reply
#5

bump
Reply
#6

Quote:
Originally Posted by introzen
Посмотреть сообщение
bump
Why are you bumping it when Jefff gave you the answer right there ?

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
stock PlayerLogin(playerid, const password[])
or if your password is a number you must convert it to string
add the 'const' bit before the password part.
Reply
#7

Quote:
Originally Posted by Haydz
Посмотреть сообщение
Why are you bumping it when Jefff gave you the answer right there ?



add the 'const' bit before the password part.
I did this. Nothing changed.
Reply
#8

pawn Код:
public OnPlayerConnect(playerid)
{
    if(CheckAccountExists(playerid) == 0) return ShowPlayerDialog(playerid,DIALOG_REGISTER,1,"Register",str,"Register","Cancel");
    else return ShowPlayerDialog(playerid,DIALOG_LOGIN,1,"Login",str1,"Login","Cancel");
}
pawn Код:
stock CheckAccountExists(playerid)
{
    new string[128];
    format(string, sizeof(string), "SELECT * FROM users WHERE username = '%s'", pName(playerid));
    mysql_query(string);
    mysql_store_result();
    new value;
    value = mysql_num_rows();
    mysql_free_result();
    return value;
}
pawn Код:
if(dialogid == DIALOG_REGISTER)
    {
        if(response)
        {
            if(strlen(inputtext[0]) < 6 || strlen(inputtext[0]) > 32) return ShowPlayerDialog(playerid,DIALOG_REGISTER,1,"Register","Password too short! Use 6-32 characters","Register","Cancel");
            PlayerRegister(playerid, inputtext);
            return 1;
        }
        else
        {
            SendInfoMessage(playerid,"You have to {a9c4e4}register {ffffff}in order to play!");
            Kick(playerid);
            return 1;
        }
    }
    if(dialogid == DIALOG_LOGIN)
    {
        if(response)
        {
            if(strlen(inputtext[0]) < 6 || strlen(inputtext[0]) > 32) return ShowPlayerDialog(playerid,DIALOG_LOGIN,1,"Login","Password too short! Use 6-32 characters","Login","Cancel");
            PlayerLogin(playerid, inputtext);
            return 1;
        }
        else
        {
            SendInfoMessage(playerid,"You have to {a9c4e4}login {ffffff}in order to play!");
            Kick(playerid);
            return 1;
        }
    }
pawn Код:
stock PlayerRegister(playerid, const password[])
{
    new str[128], pass[32];
    mysql_real_escape_string(password, pass);
    format(str,sizeof(str),"INSERT INTO users (username, password, adminlvl, level, money, skin) VALUES ('%s', md5('%s'), 0, 1, 10000, 177) ",pName(playerid),pass);
    mysql_query(str);
    SendInfoMessage(playerid,"You have been successfully registered and logged in!");
    PlayerLogin(playerid, password);
    return 1;
}

stock PlayerLogin(playerid, const password[])
{
    new str[128], pass[32];
    mysql_real_escape_string(password, pass);
    format(str,sizeof(str),"SELECT * FROM users WHERE username='%s' AND password=md5('%s') ",pName(playerid),pass);
    mysql_query(str);
    mysql_store_result();
    if(mysql_num_rows() == 0)
    {
        SendInfoMessage(playerid,"Wrong {a9c4e4}password{ffffff}! Kicked for security reasons!");
        Kick(playerid);
    }
    else
    {
        SendInfoMessage(playerid,"Successfully logged in!");
        LoadPlayerData(playerid);
    }
    mysql_free_result();
    return 1;
}
This is how the functions look right now.
Reply
#9

And sometimes I'm so stupid...

SQL table was set to "not null" on password...
All I had to do was to change
pawn Код:
pass[32]
to
pawn Код:
pass[33]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)