phpwiz Posted July 29, 2009 Share Posted July 29, 2009 ok well i am making a simple register with username, password, and confirm password. i am trying to do the md5 encryption but when they register it works fine but when they try to login it says wrong password and when i tried the encrypted password to login with it worked, can someone pease help!!! register.php <?php $submit = $_POST['submit']; // form data $username = (strip_tags($_POST['username'])); $password = (strip_tags($_POST['password'])); $repeatpassword = (strip_tags($_POST['repeatpassword'])); $date = date("Y-m-d"); $IP = $_SERVER["REMOTE_ADDR"]; $avatar = "http://www.pokemonelite2000.com/sprites/frlgemtr/frlgemtr113.png"; $cash = 250; if ($submit) { //open database $connect = mysql_connect('fdb2.awardspace.com', 'tpnrpg_main', '*********') or die("Couldnt connect"); mysql_select_db('tpnrpg_main') or die("Couldn't find db"); $namecheck = mysql_query("SELECT username FROM Users WHERE username='$username'"); $count = mysql_num_rows($namecheck); if ($count!=0) { die("This username has already been taken! <a href='register.php'>Back?</a>"); } //check for existance if ($username&&$password&&$repeatpassword) { if($password==$repeatpassword) { //check char length of username and name if (strlen($username)>35||strlen($email)>255) { echo "Length of username or name is too long! <a href='register.php'>Back?</a>"; } else { //check password length if (strlen($password)>100||strlen($password)<6) { echo "Password must be between 6 and 35 characters <a href='register.php'>Back?</a>"; } else { //register the user //encrypt password $password = md5($password); $repeatpassword = md5(repeatpassword); $queryreg = mysql_query(" INSERT INTO Users VALUES('','$username','$password','$IP','$date','','$cash','$avatar') "); die ("You have Successfully been registered! <a href='login.php'>login</a>"); } } } else echo "Your passwords do not match! <a href='register.php'>Back?</a>"; } else echo "Please fill in <b>all</b> fields! <a href='register.php'>Back?</a>"; } ?> can you please help thanks Quote Link to comment https://forums.phpfreaks.com/topic/168038-solved-md5-easy/ Share on other sites More sharing options...
gevans Posted July 29, 2009 Share Posted July 29, 2009 Where's you're login script? If everything is successfully added to the database the problem will be there, not in the register script. Quote Link to comment https://forums.phpfreaks.com/topic/168038-solved-md5-easy/#findComment-886263 Share on other sites More sharing options...
phpwiz Posted July 29, 2009 Author Share Posted July 29, 2009 login2.php <?php $username = $_POST['username']; $password = $_POST['password']; if ($username) { $connect = mysql_connect("fdb2.awardspace.com","tpnrpg_main","********") or die("Could Not connect!"); mysql_select_db("tpnrpg_main") or die("Could Not find DB"); $query = mysql_query("SELECT * FROM Users WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows!=0) { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } // check to see if they match if ($username==$dbusername&&$password==$dbpassword) { echo "You have sucessfully been logged in! <a href='mem.php'>Click here!</a>"; $_SESSION['username']=$username; $do = mysql_query("INSERT INTO Online VALUES ('$username')"); } else echo "Incorrect password!"; } else die("That user Does NOT exist"); } else die("Please enter a username and a password!"); ?> here it is. Quote Link to comment https://forums.phpfreaks.com/topic/168038-solved-md5-easy/#findComment-886273 Share on other sites More sharing options...
Mark Baker Posted July 29, 2009 Share Posted July 29, 2009 You need to hash the password that the user has entered to compare against the hashed password value that is stored in the database. Quote Link to comment https://forums.phpfreaks.com/topic/168038-solved-md5-easy/#findComment-886281 Share on other sites More sharing options...
phpwiz Posted July 29, 2009 Author Share Posted July 29, 2009 You need to hash the password that the user has entered to compare against the hashed password value that is stored in the database. Sorry i didnt understand that. hash? Quote Link to comment https://forums.phpfreaks.com/topic/168038-solved-md5-easy/#findComment-886284 Share on other sites More sharing options...
gevans Posted July 29, 2009 Share Posted July 29, 2009 You don't md5 the password sent to the script.... $password = md5($_POST['password']); Quote Link to comment https://forums.phpfreaks.com/topic/168038-solved-md5-easy/#findComment-886285 Share on other sites More sharing options...
phpwiz Posted July 29, 2009 Author Share Posted July 29, 2009 You don't md5 the password sent to the script.... $password = md5($_POST['password']); WHat are you talking about. Quote Link to comment https://forums.phpfreaks.com/topic/168038-solved-md5-easy/#findComment-886286 Share on other sites More sharing options...
gevans Posted July 29, 2009 Share Posted July 29, 2009 WHat are you talking about. What don't you understand. You're comparing a plain text password to a md5 hashed password Quote Link to comment https://forums.phpfreaks.com/topic/168038-solved-md5-easy/#findComment-886293 Share on other sites More sharing options...
phpwiz Posted July 29, 2009 Author Share Posted July 29, 2009 WHat are you talking about. What don't you understand. You're comparing a plain text password to a md5 hashed password soo what do i put where to fix this? Quote Link to comment https://forums.phpfreaks.com/topic/168038-solved-md5-easy/#findComment-886295 Share on other sites More sharing options...
Mark Baker Posted July 29, 2009 Share Posted July 29, 2009 The password is stored as an md5 hashed value on the database e.g. a3fcb295b... The user enters their password as plain text e.g. bonzo You compare "a3fcb295b..." with "bonzo" and the two values are clearly not the same. You need to hash the value (bonzo) entered by the user to get its hash value (a3fcb295b...), then compare the two values if ($username==$dbusername&&md5($password)==$dbpassword) Quote Link to comment https://forums.phpfreaks.com/topic/168038-solved-md5-easy/#findComment-886299 Share on other sites More sharing options...
gevans Posted July 29, 2009 Share Posted July 29, 2009 $password = md5($_POST['password']); Remember that? it goes in place of $password = $_POST['password']; Quote Link to comment https://forums.phpfreaks.com/topic/168038-solved-md5-easy/#findComment-886300 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.