Specifications

LISTING 28.12 change_password() Function from user_auth_fns.phpThis Function
Validates and Updates a Users Password
function change_password($email, $old_password, $new_password,
$new_password_conf)
// change password for email/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 return false
if (login($email, $old_password))
{
if($new_password==$new_password_conf)
{
if (!($conn = db_connect()))
return false;
$query = “update subscribers
set password = password(‘$new_password’)
where email = ‘$email’”;
$result = mysql_query($query);
return $result;
}
else
echo “<p> Your passwords do not match.”;
}
else
echo “<p> Your old password is incorrect.”;
return false; // old password was wrong
}
This function is similar to other password setting and changing functions we have looked at.
It compares the two new passwords entered by the user to make sure they are the same, and if
they are, tries to update the users password in the database.
Logging Out
When a user clicks on the Log Out button, it triggers the log-out action. The code executed by
this action in the main script is actually in the preprocessing section of the script, as follows:
if($action == ‘log-out’)
{
session_destroy();
unset($action);
Building a Mailing List Manager
C
HAPTER 28
28
BUILDING A
MAILING LIST
MANAGER
691
34 7842 CH28 3/6/01 3:46 PM Page 691