hey people,
having trouble with a change password script that should allow users to do the obvious.
most the validation works, but when i input the correct old password and define two same new passwords and submit, i get nothing and the password is not changed so im thinking theres something wrong with my 'update' piece of code.
heres my code:
// create short variable names
$old_password = $_POST['old_password'];
$new_password = $_POST['new_password'];
$new_password2 = $_POST['new_password2'];
//check valid user
if (isset($_SESSION['valid_user']))
{
echo 'Logged in as '.$_SESSION['valid_user'].'.';
echo '<br />';
}
else
{
// they are not logged in
echo 'You are not logged in.<br />[<a href=login.php>login</a>]';
exit;
}
// check forms filled in
if (!filled_out($_POST))
{
echo 'You have not filled the form out completly - please go back'
.' and try again.<br />';
exit;
}
if ($new_password!=$new_password2)
echo 'The new passwords you entered do not match - please go back'
.' and try again.<br />Your password has not been changed.<br />';
exit;
if (strlen($new_password)>16 || strlen($new_password)<6)
echo 'Your password must be between 6 and 16 characters - '
.'please go back and try again.<br />';
exit;
// attempt update
//change_password($_SESSION['valid_user'], $old_password, $new_password);
// if the old password is right
// change their password to new_password and return true
// else throw an exception
//login
// connect to db
$mysql_database="dbname";
$mysql_username="username";
$mysql_password="pass";
$dbconnect = mysql_connect("localhost",$mysql_username,$mysql_password) or die ("Unable to connect to SQL server");
mysql_select_db($mysql_database,$dbconnect) or die ("Unable to select database");
// check if username is unique
$result = mysql_query("select * from BWmembers where username='$username' and password = sha1('$password')")
or die ("Could not log you in.");
if (mysql_num_rows($result)) {
echo 'Successful Login<br />';
// set session username
$_SESSION['valid_user'] = $username;
}
else {
echo 'Failed Login<br />[<a href=login.php>login</a>]';
exit;
}
//update password
$result = mysql_query("update BWmembers set password = sha1('$new_password') where username = '$username'")
or die ("Database update failed.");
if (!$result){
echo 'Password could not be changed.';
exit;
}
else {
echo 'Password changed.';
}
any help would be very much apreciated,
thanks.