phprick Posted August 11, 2012 Share Posted August 11, 2012 i made a script to change the password if i file in the form i get a message that my password is changed but it doesnt :'( please help me thanks in advanced if($_POST['submit']=='Set') { // If the change form has been submitted $err = array(); $usr = $_SESSION['usr']; $newpass = $_POST['newpass']; $passorig = mysql_query("SELECT pass FROM tz_mebers WHERE usr=$usr"); $email = mysql_query("SELECT email FROM tz_mebers WHERE usr=$usr"); if(!$_POST['oldpassword'] == $passorig) { $err[]='Your password is incorrect!'; } if(!$_POST['newpass'] == $_POST['vnewpass']) { $err[]='Your passwords do not match!'; } if(!count($err)) { // If there are no errors $pass = md5($_POST['newpassword']); // Generate a random password $_POST['newpassword'] = mysql_real_escape_string($_POST['newpassword']); // Escape the input data mysql_query("UPDATE tz_members SET pass=$newpass WHERE usr=$usr"); send_mail( '[email protected]', $email, 'ClephasWebdesign member registration - Your New Password', 'Your password is: '.$pass); $_SESSION['msg']['cha-success']='Your password is set succesfull!'; } if(count($err)) { $_SESSION['msg']['cha-err'] = implode('<br />',$err); } header("Location: home.php"); exit; } <form action="" method="post"> <h1>Change Your Password</h1> <?php if($_SESSION['msg']['cha-err']) { echo '<div class="err">'.$_SESSION['msg']['cha-err'].'</div>'; unset($_SESSION['msg']['cha-err']); } if($_SESSION['msg']['cha-success']) { echo '<div class="success">'.$_SESSION['msg']['cha-success'].'</div>'; unset($_SESSION['msg']['cha-success']); } ?> <label class="grey" >Old Password:</label> <input class="field" type="password" name="oldpass" id="oldpass" value="" size="23" /> <label class="grey" >New Password:</label> <input class="field" type="password" name="newpass" id="newpass" value="" size="23" /> <label class="grey" >Verify New Password:</label> <input class="field" type="password" name="vnewpass" id="vnewpass" value="" size="23" /> <input type="submit" name="submit" value="Set" class="bt_register"/> </form> Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/ Share on other sites More sharing options...
Porl123 Posted August 11, 2012 Share Posted August 11, 2012 You're comparing the user inputted field with a query, you know. You need to fetch the row before you can compare its fields. $query = mysql_query("SELECT pass, email FROM tz_mebers WHERE usr=$usr"); $user = mysql_fetch_array($sql); echo 'Email: '.$user['email'].' Password: '.$user['pass']; Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368550 Share on other sites More sharing options...
phprick Posted August 11, 2012 Author Share Posted August 11, 2012 yes i know i forget sorry but it is stil not changing Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368551 Share on other sites More sharing options...
Porl123 Posted August 11, 2012 Share Posted August 11, 2012 In the select queries you're referring to the table tz_mebers and in the update query you're updating tz_members. Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368552 Share on other sites More sharing options...
phprick Posted August 11, 2012 Author Share Posted August 11, 2012 ok yes but than he shoot change ?? Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368556 Share on other sites More sharing options...
Porl123 Posted August 11, 2012 Share Posted August 11, 2012 if(!md5($_POST['oldpassword']) == $passorig) { $err[]='Your password is incorrect!'; } The original password should be put through the md5 function to make the comparison. Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368557 Share on other sites More sharing options...
phprick Posted August 11, 2012 Author Share Posted August 11, 2012 i changed that md5 but now it say Your password is incorrect Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368559 Share on other sites More sharing options...
Porl123 Posted August 11, 2012 Share Posted August 11, 2012 Yeah, your update query updates your password to $newpass, which is the version of the password before it went through the md5. So the password stored in the database isn't encrypted. Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368560 Share on other sites More sharing options...
phprick Posted August 11, 2012 Author Share Posted August 11, 2012 yes but he do not change in anything and de Original password is incorrect with md5 without md5 i can type anyting Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368562 Share on other sites More sharing options...
phprick Posted August 11, 2012 Author Share Posted August 11, 2012 than he has to change in the normal tekst right?? Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368564 Share on other sites More sharing options...
Porl123 Posted August 11, 2012 Share Posted August 11, 2012 What error messages are you getting? Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368565 Share on other sites More sharing options...
phprick Posted August 11, 2012 Author Share Posted August 11, 2012 no error it say that the password change but in my database it isnt Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368567 Share on other sites More sharing options...
Porl123 Posted August 11, 2012 Share Posted August 11, 2012 Ah I see, well add "or die(mysql_error())" at the end of your query. Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368568 Share on other sites More sharing options...
phprick Posted August 11, 2012 Author Share Posted August 11, 2012 i dit the this mysql_query("UPDATE tz_members SET pass=$pass WHERE usr=$usr")or die(mysql_error()); but it stil say that old password is incorrect Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368569 Share on other sites More sharing options...
Porl123 Posted August 11, 2012 Share Posted August 11, 2012 Well yeah, because the password in the database won't be encrypted. Take the md5 off for a moment. Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368571 Share on other sites More sharing options...
phprick Posted August 11, 2012 Author Share Posted August 11, 2012 this is what i get Unknown column 'rick' in 'where clause' Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368572 Share on other sites More sharing options...
Christian F. Posted August 11, 2012 Share Posted August 11, 2012 First and foremost I'd just like to point out that MD5 was found broken in 2006, meaning it would take only one minute to find a collision with a laptop computer back then. So, don't use MD5 for passwords. Secondly, you'll always want to use a individual salt per user when hashing the password, and change this salt every time the password is changed. Read the thread "What's the point of MD5", and you will be a bit more enlightened. Just remember to read the entire thread, as there are quite a lot of misconceptions posted inside of it. Best advice comes in the final post. Once you've done that, update your code and post the updated version here, if you still have problems with it. Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368573 Share on other sites More sharing options...
phprick Posted August 11, 2012 Author Share Posted August 11, 2012 ok Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368574 Share on other sites More sharing options...
phprick Posted August 11, 2012 Author Share Posted August 11, 2012 i have one more question how can i make a folder under oder folder in php Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368575 Share on other sites More sharing options...
jazzman1 Posted August 11, 2012 Share Posted August 11, 2012 if(!md5($_POST['oldpassword']) == $passorig) { $err[]='Your password is incorrect!'; } The original password should be put through the md5 function to make the comparison. I think this logic is wrong. Simple example: // incorrect $pass = "password"; $passMd5 = md5('password'); if(!$passMd5 == md5($pass)){ var_dump($passMd5); } // correct $pass = "password"; $passMd5 = md5('password'); if($passMd5 == md5($pass)){ var_dump($passMd5); } //correct $pass = "password"; $passMd5 = md5('password'); if(!$passMd5 != md5($pass)){ var_dump($passMd5); } Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368579 Share on other sites More sharing options...
Christian F. Posted August 11, 2012 Share Posted August 11, 2012 Actually, that logic is correct. Provided that he'd tested the correct values, that is. Not that I disagree with you that he should have written it in a more simple manner, to make it easier to read and maintain. The test parses as following: // Starting point. if (!$Hash == md5 ($Pass) { // Since $Hash and md5 ($Pass) equals, the comparison returns true. if (!true) { // Not true == false, thus the IF-block is skipped and we know the password is correct. if (false) { $err[] = '' } Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368580 Share on other sites More sharing options...
jazzman1 Posted August 11, 2012 Share Posted August 11, 2012 Actually, that logic is correct. Are you sure ? $pass = "password"; $passMd5 = md5('password'); if(!$passMd5 == md5($pass)){ var_dump($passMd5); } else { var_dump(false); } Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368581 Share on other sites More sharing options...
Christian F. Posted August 11, 2012 Share Posted August 11, 2012 Seems I did indeed forget about the operator precedence. Sorry about that. The correct interpretation of how PHP parses it: // Starting point. if (!$Hash == md5 ($Pass) { // Since ! has precedence, it changes a string to BOOL FALSE. if (false == md5 (pass)) { // A string with content is always != false, thus the test will always fail. if (false) { $err[] = '' } Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368582 Share on other sites More sharing options...
jazzman1 Posted August 11, 2012 Share Posted August 11, 2012 No problem. Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368584 Share on other sites More sharing options...
Christian F. Posted August 11, 2012 Share Posted August 11, 2012 I did, then I had some second thoughs and tested the inverse. Thus my edit above. Sorry a bout all of the confusion, I'm ashamed of myself. Link to comment https://forums.phpfreaks.com/topic/266940-php-password-change/#findComment-1368585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.