Our Scripts Vault contains many game scripts that you can use to create your own game!
$sqlfind = sprintf("select * from players where username = '$playername' and (password) = ('%s');", mysql_real_escape_string(md5('$playerpassword')));
$sqlfind = sprintf("select * from players where username = '%s' and password = '%s'", $playername, mysql_real_escape_string(md5('$playerpassword')));
I THINK the problem is that you are trying to put a variable inside without using the %s thing. the query is literally looking for someone with the username $playername. do the same thing you did with the password and it should work.Code: [Select]$sqlfind = sprintf("select * from players where username = '%s' and password = '%s'", $playername, mysql_real_escape_string(md5('$playerpassword')));
@emicarn Did you try to print the $sqlfind variable? Try echo $sqlfind and use it in phpMyAdmin, if it works, the problem is somewhere else (and we'd need to see more of the code)
Quote from: Sagefire135 on December 23, 2010, 10:57:11 PMI THINK the problem is that you are trying to put a variable inside without using the %s thing. the query is literally looking for someone with the username $playername. do the same thing you did with the password and it should work.Code: [Select]$sqlfind = sprintf("select * from players where username = '%s' and password = '%s'", $playername, mysql_real_escape_string(md5('$playerpassword'))); No, that isnt the problem. Or my whole game wouldnt work. Can we see the query putting the data into the players table?
$adduser = sprintf("INSERT INTO players (username, password, email, shipname, faction, pos_x, pos_y, class, beta_tester, admin, confirmed, vessel_val, points, v_points, c_hull, c_shield, c_engine, c_battery, c_aux_power, c_sensors, c_beam_weapon, c_torpedo_weapon, c_dc, c_transporters, c_crew, c_marines, c_torpedos, m_hull, m_shield, m_engine, m_battery, m_aux_power, m_sensors, m_beam_weapon, m_torpedo_weapon, m_dc, m_transporters, m_crew, m_marines, m_torpedos, join_date, join_time, login_date, login_time) values ('%s', '%s', '%s', '%s', '%s', '$posX', '$posY', 'Gun Boat', '$isbeta_tester', '$isadmin', '$isconfirmed', '47', '0', '0', '10', '10', '10', '5', '5', '1', '2', '1', '5', '1', '10', '5', '10','10', '10', '10', '5', '5', '1', '2', '1', '5', '1', '10', '5', '10', '$date', '$time', '$date', '$time');", mysql_real_escape_string($playername), mysql_real_escape_string(md5($playerpassword)), mysql_real_escape_string($playeremail), mysql_real_escape_string($playershipname), mysql_real_escape_string($playerfaction));
$queryPattern = "SELECT * FROM players WHERE username = '%s' AND password = '%s';";$sqlfind = sprintf($queryPattern, mysql_real_escape_string($playername), md5($playerpassword));
The issue here is that you have single quotes around the $playerpassword variable inside of your md5() call. Thus, you're ALWAYS getting the md5 hash of the string '$playerpassword' instead of the user-entered password that you're expecting.Try the following instead (minor re-write):Code: (php) [Select]$queryPattern = "SELECT * FROM players WHERE username = '%s' AND password = '%s';";$sqlfind = sprintf($queryPattern, mysql_real_escape_string($playername), md5($playerpassword));As a note, you can also use && in place of AND in the query. I prefer using && to keep it consistent with other programming languages' logical evaluation operators. But that's just personal preference. *Edit - Wrote query inside of a variable to prevent code scrolling in my forum theme.
Did you remove the hashing only for the select query? Or for the insert as well? Perhaps you'd already created an md5 hash of the password earlier in your code?Essentially, were you hashing an already hashed password (this will generate a different hash)?
Did you try to echo and compare the md5's?Do you have sufficient column length? MD5 needs 32chars, if the limit is shorter, it gets cropped and therefore do not match
I have the password field set to varchar(25) Let me adjust that to a bigger field and see what happens.
Quote from: emicarn on December 24, 2010, 03:40:13 PMI have the password field set to varchar(25) Let me adjust that to a bigger field and see what happens.Ah, there's the culprit! As a tip, you can declare this column as char(32) instead of varchar(32) since an md5 hash is always 32 characters long. Not much of an optimization, but it does save 1 byte or 2 per player since it's no longer necessary to store the length of the string.