Hooo Posted August 26, 2009 Share Posted August 26, 2009 Here is what I have, the basic aim of the script is to change password, does a couple of checks like Old password matches password they input on the previous form, and new password matches the new password confirm box in the form also. I know it is bad as it is, I have been trying to fix it, however things are just not going well At the moment with the code I have it says "The two passwords didn't match.. Thanks for any help given. <html> <body> <?php include 'config.php'; include 'opendb.php'; session_start(); if(isset($_SESSION['usname'])) { ?> <table width="320" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form name="changepw" method="post" action="changepw1.php"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3"><strong> Change Your Password </strong></td> </tr> <tr> <td width="200">Old Password</td> <td width="6">:</td> <td width="294"><input name="opass" type="password" id="opass"></td> </tr> <tr> <td>New Password</td> <td>:</td> <td><input name="npass" type="password" id="npass"></td> </tr> <tr> <td>Re-enter</td> <td>:</td> <td><input name="npass1" type="password" id="npass1"></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Change Password"></td> </tr> </table> </td> </form> </tr> </table> <?php } else { echo '<meta http-equiv="refresh" content="2;url=index.php">'; } ?> </body> </html> and <?php include 'config.php'; include 'opendb.php'; session_start(); $opass = $_POST["opass"]; $npass = $_POST["npass"]; $npass1 = $_POST["npass1"]; $salt = 's+(_a*'; $salt_passo = md5($opass.=$salt); $salt_passn = md5($npass.=$salt); $result = mysql_query("SELECT userpass FROM Users WHERE usname = '{$_SESSION['usname']}'") or die(mysql_error()); $row=mysql_fetch_assoc($result); if(isset($_SESSION['usname'])) { if ($salt_passo != $row['userpass']) { echo "Your old password was entered incorrectly"; } elseif ($npass != $npass1) { echo "The two new password didn't match"; } else { mysql_query("UPDATE `Users` SET `userpass`='{$salt_passn}' WHERE `usname` = '{$_SESSION['usname']}'") or die("Error: ".mysql_error()); } } else { echo '<meta http-equiv="refresh" content="2;url=index.php">'; } ?> Quote Link to comment Share on other sites More sharing options...
gamerx Posted August 26, 2009 Share Posted August 26, 2009 <html> <body> <?php include 'config.php'; include 'opendb.php'; session_start(); if(isset($_SESSION['usname'])) { //if the username session var is set if(isset($_POST["submitbtn"])) { $opass = $_POST["opass"]; $npass = $_POST["npass"]; $npass1 = $_POST["npass1"]; $salt = 's+(_a*'; $salt_passo = md5($opass.=$salt); $salt_passn = md5($npass.=$salt); $result = mysql_query("SELECT userpass FROM Users WHERE usname = '{$_SESSION['usname']}'") or die(mysql_error()); $row=mysql_fetch_assoc($result); if($npass == $npass1) { if ($salt_passo != $row['userpass']) { echo "Your old password was entered incorrectly"; } else { //save the password (this code need fixing too, but i think you knew that... mysql_query("UPDATE `Users` SET `userpass`='{$salt_passn}' WHERE `usname` = '{$_SESSION['usname']}'") or die("Error: ".mysql_error()); } } else { //passwords don match echo "The two new password didn't match"; } } else { $thisscript = $_SERVER['PHP_SELF']; //sets this echo' <table width="320" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form name="changepw" method="post" action="'.$thisscript.'"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3"><strong> Change Your Password </strong></td> </tr> <tr> <td width="200">Old Password</td> <td width="6">:</td> <td width="294"><input name="opass" type="password" id="opass"></td> </tr> <tr> <td>New Password</td> <td>:</td> <td><input name="npass" type="password" id="npass"></td> </tr> <tr> <td>Re-enter</td> <td>:</td> <td><input name="npass1" type="password" id="npass1"></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="submitbtn" value="Change Password"></td> </tr> </table> </td> </form> </tr> </table> '; } } ?> </body> </html> try that, maybe a few edits also this all goes into the one file... Quote Link to comment Share on other sites More sharing options...
Hooo Posted August 27, 2009 Author Share Posted August 27, 2009 Took out the extra <html> and opening PHP at the top which crashed the page, but when I try to change I still get "the two passwords didn't match" Quote Link to comment Share on other sites More sharing options...
Hooo Posted August 27, 2009 Author Share Posted August 27, 2009 If nobody can make sense of my code, is there an easier way I can do this? Sorry for double post Quote Link to comment 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.