Location: PHPKode > projects > Scriptorium > scriptorium1.6/user_management/send_password_reminder.php
<?php

include('../includes/scriptorium_inc.php');

/**
 * Return a random string
 *
 * @author       Aidan Lister <hide@address.com>
 * @version      2.0
 * @param        int     $length  Length of the string you want generated
 * @param        string  $seeds   The seeds you want the string to be generated from
 */
function str_rand($length = 8, $seeds = 'abcdefghijklmnopqrstuvwxyz0123456789')
{
    $str = '';
    $seeds_count = strlen($seeds);
 
    // Seed
    list($usec, $sec) = explode(' ', microtime());
    $seed = (float) $sec + ((float) $usec * 100000);
    mt_srand($seed);
 
    // Generate
    for ($i = 0; $length > $i; $i++) {
        $str .= $seeds{mt_rand(0, $seeds_count - 1)};
    }
 
    return $str;
}

if ($_POST['submit'] != '') {
  // validate input
  if ($_POST['email'] == '') {
    header('Location: ../forgot_password.php');
    exit();
  }

  $quoted_email = $db->quoteSmart(strtolower($_POST['email']));

  //does this email address already exist in the database?
  $sql = "SELECT name, username FROM scriptorium_users WHERE email=$quoted_email";

  $row = $db->getRow($sql,DB_FETCHMODE_ASSOC);

  if (!is_array($row)) {
    header('Location: ../index.php');
    exit();
  } else {
    // autogenerate a new password
    $newpassword = str_rand(10);
    $sql = "UPDATE scriptorium_users SET password=PASSWORD('$newpassword') WHERE email=$quoted_email";
    $result = $db->query($sql);
    
    if ($db->isError($result)) {
      $_SESSION['message'] = lib('reminder_send_error');
      header('Location: ../forgot_password.php');
      exit();
    }

    // send the reminder email
    $name = stripslashes($row['name']);
    $username = stripslashes($row['username']);

    $email_subject = lib('reminder_subject', NAME);
    $email_recipient = "$name <{$_POST['email']}>";
    $account_details = lib('account_details', NAME);
    $reminder_secure = lib('reminder_secure', NAME);
    $web_link = WEB_PATH . '/login.php';
    
	
    $email_body = <<<TEXT

$account_details:

  {$libs['username']}: $username
  {$libs['password']}: $newpassword
            
$reminder_secure

$web_link


TEXT;

    mail($email_recipient,$email_subject,$email_body);
    $_SESSION['message'] = $_POST['email'];

    header('Location: ../reminder_sent.php');
    exit();  

  }
  
 }


Return current item: Scriptorium