Jump to content

[SOLVED] Change Password Script (Please :'( )


Hooo

Recommended Posts

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">';
}

?>

Link to comment
Share on other sites

<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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.