EchoFool Posted May 26, 2009 Share Posted May 26, 2009 I have a login page which uses the same md5 encryption to check if the password is correct and also on the "change password" page which also md5 encrypts the input to see if it matches the database, how ever the same word comes out with two different md5 results. I am getting it right because i logged in using the password and it lets me login which works fine... so i paste that exact same password to my change password page where it asks for current password to continue, and some how the md5 password result is totally different to what is in the database, yet the login script creates the correct one..... i don't get why... this is what i have: <?php $old = md5(strtolower(mysql_real_escape_string($_POST['OldPass']))); // the password currently $pass = strtolower(mysql_real_escape_string($_POST['Pass'])); //the new password not encrypted $npass = md5($pass); // new password encrypted $npass2 = strtolower(mysql_real_escape_string($_POST['Pass2'])); // re-enter passwords make sure its correct $npass2 = md5($npass2); //encrypt it to see if it matches $npass $check = mysql_query("SELECT UserID FROM users WHERE UserID='{$_SESSION['Current_User']}' AND Password='$old'") Or die(mysql_error()); If(mysql_num_rows($check)>0){ Echo 'success'; }Else{ Echo 'failed'; } ?> As you can guess i get Failed. Now on mylogin page i have this: <?php $Password = md5(strtolower(mysql_real_escape_string($_POST['Password']))); $Username = strtolower(mysql_real_escape_string($_POST['Username'])); $check2 = mysql_query("SELECT UserID,Password FROM users WHERE Username='$Username'") Or die(mysql_error()); $row = mysql_fetch_assoc($check2); If($row['Password'] == $Password){ Echo 'success'; }Else{ echo 'failed'; } ?> As you can probably guess it says "success"... which is what is meant to happen.. so why do you think the first script is not producing the same md5 result? Quote Link to comment https://forums.phpfreaks.com/topic/159774-md5-different-results-on-same-input/ Share on other sites More sharing options...
MadTechie Posted May 26, 2009 Share Posted May 26, 2009 Looks like the username is the problem! maybe start_session(); have you tried echoing the results! Quote Link to comment https://forums.phpfreaks.com/topic/159774-md5-different-results-on-same-input/#findComment-842772 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.