Example #1
0
require_once 'scripts/classes.php';
require_once 'scripts/logout.php';
//===============================================================================
//	INCOMING INFORMATION
//===============================================================================
if (isset($_SESSION['access'])) {
    // Redirect to members area.
    header('Location:members_area.php?' . ($_SESSION['access'] === "staff" ? 'view=' . $_SESSION['id'] : ""));
}
// Determine the action we're trying to take.
if (isset($_POST['submit']) && (isset($_GET['forgotpassword']) or isset($_POST['forgotpassword']))) {
    // Looks like we forgot our password.
    $random_hash = md5(uniqid(rand(), true));
    $new_pass = strtoupper(substr($random_hash, strlen($random_hash) % 2, 10));
    // Get information submitted to the page.
    if (User::emailPassword($_POST['email'], $new_pass)) {
        // collect the form valus
        $email_message = "Thank you for using the automated password retrieval system.\n\n\tPassword:"******"\n\nPlease log into the system using the above password.";
        // set the email properties
        $to = $_POST['email'];
        $subject = "Password reset information.";
        $from = "*****@*****.**";
        $headers = "From: support@tps.com";
        // attempt to send the mail, catch errors if they occur
        try {
            mail($to, $subject, $email_message, $headers);
            $message = '<p style="margin: 0px; margin-left: 8px; margin-right: 8px;">An email has been sent to the email provided. Please check your email for more details.</p>';
        } catch (Exception $e) {
            $message = "An Exception was thrown: " . $e->getMessage() . "<br>";
        }
    } else {