MySQL Forums
Forum List  »  PHP

Changing Password Script - Please Help!!!
Posted by: Refon Miah
Date: November 12, 2005 08:39PM

Hi. I am using PHP5 and MySQL5, running on Apache Server on Windows XP.
I am trying to use the scripts below to change a user's password, but i get the message saying 'Password Could not be changed' (Line 15 in the second script).

(change_passwd.php)
=========================================================
<?php
require_once('manormotors_fns.php');
session_start();
do_html_header('Changing password');

$old_passwd = $_POST['old_passwd'];
$new_passwd = $_POST['new_passwd'];
$new_passwd2 = $_POST['new_passwd2'];

try
{
check_valid_user();
if (!filled_out($_POST))
throw new Exception('You have not filled out the form completely.'
.' Please try again.');
if ($new_passwd!=$new_passwd2)
throw new Exception('Passwords entered were not the same. Not changed.');
if (strlen($new_passwd)<6)
throw new Exception('New password must be at least 6 characters.'
.' Try again.');
// attempt update
change_password($_SESSION['valid_user'], $old_passwd, $new_passwd);
echo 'Password changed.';
}

catch (Exception $e)
{
echo $e->getMessage();
}
display_user_menu();
do_html_footer();
?>
===========================================================

and

change_passwd function (in user_auth_fns.php)
===========================================================
function change_password($username, $old_password, $new_password)
// change password for username/old_password to new_password
// return true or false

{
// if the old password is right
// change their password to new_password and return true
// else throw an exception
login($username, $old_password);
$conn = db_connect();
$result = $conn->query( "update user
set passwd = '$new_password'
where username = '$username'");
if (!$result)
throw new Exception('Password could not be changed.');
else
return true; // changed successfully
}
============================================================

Please help me!!! I am Really stuck!

Options: ReplyQuote


Subject
Written By
Posted
Changing Password Script - Please Help!!!
November 12, 2005 08:39PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.