behrk2 Posted October 1, 2007 Share Posted October 1, 2007 Hey all, I have a question. I am setting up a registration/login for my website with PHP and MYSQL. I have a register.html, register.php & a login.html, login.php. I can successfully register a user (using register.html, register.php) into my database. Now, I am trying to authenticate the user with the login.html, login.php. When I try to do so, however, I always recieve my error message "failed." It will not authenticate (despite several attempts of logging in with the same username and password of that which is in my database.) Here is my code for login.php: <?php $dbhost = "localhost"; $dbname = "hub_info"; $dbuser = "xxxxxx"; $dbpass = "xxxxxx"; mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); session_start(); $username = $_POST['username']; $password = md5($_POST['password']); $query = mysql_query("SELECT * FROM ra_info WHERE username='$username' AND password='$password'"); if (mysql_num_rows($query)<1) { print "failed"; } else { $_SESSION["username"]; $_SESSION["password"]; print "You are now logged in."; } ?> Does anyone have any ideas? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/71437-solved-phpmysql-login/ Share on other sites More sharing options...
trq Posted October 1, 2007 Share Posted October 1, 2007 Are you sure you didn't md5 your passwords? You should have. Quote Link to comment https://forums.phpfreaks.com/topic/71437-solved-phpmysql-login/#findComment-359575 Share on other sites More sharing options...
MmmVomit Posted October 1, 2007 Share Posted October 1, 2007 Get rid of the password clause in your sql statement. Just query for records where the username matches, then print to screen the hash of the supplied password and the hash retrieved from the database. This will help tell you why the login is failing. Quote Link to comment https://forums.phpfreaks.com/topic/71437-solved-phpmysql-login/#findComment-359576 Share on other sites More sharing options...
Orio Posted October 1, 2007 Share Posted October 1, 2007 One common mistake that may happen when dealing with md5 (or other hashes) is not giving them enough space. By that I mean, that the password column maybe too small- less than 32 chars. Check that. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/71437-solved-phpmysql-login/#findComment-359577 Share on other sites More sharing options...
behrk2 Posted October 1, 2007 Author Share Posted October 1, 2007 thanks for the quick responses, guys The problem was that i did not allocate enough space for the password column...i only gave 15 characters. I changed it to 50 and now it works fine. Thanks so much, I never would have realized that! Quote Link to comment https://forums.phpfreaks.com/topic/71437-solved-phpmysql-login/#findComment-359583 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.