PDA

View Full Version : Mysql | Always wrong password


thefatshizms
23/01/2013, 05:52 PM
Hello, when i enter the correct password it always says that it's incorrect.. I have no idea where I have gone wrong and been trying different things to fix it but.. no luck
public Mysql_Login(playerid, password[])
{
mysql_real_escape_string(PlayerName(playerid), PlayerName(playerid));
mysql_real_escape_string(password, password);
new Hash[129], Query[500];
WP_Hash(Hash, 129, password);
format(Query, 500, "SELECT * FROM `users` WHERE `username` = '%s' AND `password` = '%s'", PlayerName(playerid), Hash);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() == 1)
{
SendClientMessage(playerid, COLOR_WHITE, "You have been logged in and your {FF0000}stats are loaded");
LoggedIn[playerid] = 1;
}
else
{
SendClientMessage(playerid, -1, "Wrong password");
}
mysql_free_result();
return 1;
}

Sweez
23/01/2013, 05:59 PM
public Mysql_Login(playerid, password[])
{
mysql_real_escape_string(PlayerName(playerid), PlayerName(playerid));
mysql_real_escape_string(password, password);
new Hash[129], Query[500];
WP_Hash(Hash, 129, password);
format(Query, 500, "SELECT * FROM `users` WHERE `username` = '%s' AND `password` = '%s'", PlayerName(playerid), Hash);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() == 1)
{
SendClientMessage(playerid, COLOR_WHITE, "You have been logged in and your {FF0000}stats are loaded");
LoggedIn[playerid] = 1;
}
else
{
SendClientMessage(playerid, 0, "Wrong password");
}
mysql_free_result();
return 1;
} Try this, if it doesnt work i cant help you, sorry !

thefatshizms
23/01/2013, 07:07 PM
All you have changed is the colour ...

FUNExtreme
23/01/2013, 07:16 PM
First: have you tried running the query in phpmyadmin to see if it is correct and what it returns?
Second: have you tried printing everything, the hashed password, the received information, ..

thefatshizms
23/01/2013, 07:21 PM
Yes i've tried the printing. Also, within the mysql debug it says that the result returns 0 results though, when i look in the phpmyadmin my name and pass etc is there.

FUNExtreme
23/01/2013, 07:23 PM
the mysql debug it says that the result returns 0 results

Do more debugging until you find out why it returns 0. It would return at least one row if your query was correct.

thefatshizms
23/01/2013, 07:46 PM
Ok, i have looked into it and i can see that it's all doing fine, hashing etc i look into the phpmyadmin and not all the hash is in there, like 1/4 is missing so... how do i fix this?

(note: in debug in the query its displaying its inserting the WHOLE hash but while it was querying it must of been shortened or somethin)

DanLore
23/01/2013, 07:51 PM
In your MySQL database, check the size of the password field, if some is cut off then this could be the issue. You should determine the max size of the hashed password, and then adjust the table structure accordingly..

thefatshizms
23/01/2013, 08:13 PM
Ah yes, i forgot about that. The length at this moment is 100 which explains why the full length of the hash wasn't getting in. Thanks :)