Location: PHPKode > projects > Communication Kit > programs/live/lost_pw_inc.php
<?php
class ck_lost_pw {
  var $page_ref = '';
  var $ob = "" ; //order by
  var $ob_dir = "" ; //order by direction
  var $ob_next = "" ; //order by next
  var $update_actions = Array('update','add','del','delmem');
  var $display_actions = Array('edit');
  function update_page($action){
    global $error_text;

    // process data, (if a form has been submitted)
    if (isset($_POST['hidden_field'])){
      $username   = stripslashes($_POST['username']);
      $sql = mysql_query("SELECT * FROM ".USERS."
        WHERE username='$username' AND activated='1'");
      $login_check = mysql_num_rows($sql);
      if($login_check <> 1){
        $error_text.= "Username not recognised.";
        unset($username);
      }
      else{
        while($row = mysql_fetch_array($sql)){
          foreach( $row AS $key => $val ){
            $$key = stripslashes( $val );
          }
        }
        function makeRandomPassword(){
          $pass="";
          $salt = "abchefghjkmnpqrstuvwxyz0123456789";
          srand((double)microtime()*1000000);
          $i = 0;
          while ($i <= 7){
            $num = rand() % 33;
            $tmp = substr($salt, $num, 1);
            $pass = $pass . $tmp;
            $i++;
          }
          return $pass;
        }
        $random_password = makeRandomPassword();
        $db_password = md5($random_password);
        $sql = mysql_query("UPDATE ".USERS." SET password='$db_password' WHERE userid='$userid'")
        or die (mysql_error());
        $dir_name = dirname($_SERVER['PHP_SELF']);
        $subject = "New Password for ".$_SESSION['sess_site_title'];
        $message = "Dear $first_name,

You have requested a new password.

Please use the password below,
then change it to something you will remember!

Username: $username
Password: $random_password

Thank you.


This is an automated response, please do not reply!";
        mail($email_address, $subject, $message, "From: ".$_SESSION['sess_site_title']."<".$_SESSION['sess_webm_email'].">\n");
        $error_text.= "A new password has been emailed to you.";
      }
    }
  }
  function display_page($action){
    print "<p class=small_text>To receive a new password, please enter your username...</p>";
      $GLOBALS['validate']=TRUE;
      $GLOBALS['form']=TRUE;
    ?>
<script language="JavaScript">
var objValidation = new Object();
function SetValidation(){
  objValidation.username = new Object();
  objValidation.username.type = 'text';
  objValidation.username.blank = false;
  objValidation.username.valtext = 'Your username';
}
function submit_it(){
  if (Validate(document.form, objValidation))
  document.form.submit();
  else
  return false;
}
</script>

<form name="form" method="post" action="<?=$_SERVER['PHP_SELF']."?page_ref=$this->page_ref"?>">
<table border="0" cellpadding="4" cellspacing="0">
<tr><td class="small_text" align="right">Your username</td>
    <td class="reset"><input name="username" type="text" class=text maxlength="12" size="12" value=""  onBlur="Validate(document.lost_pw_form, objValidation, this.name);"></td>
</tr>
<tr><input type="hidden" name="hidden_field" value="entered">
<td>&nbsp;</td>
<td class="reset"><input type="button" name="Submit" value="Send" onClick="submit_it();"></td>
</tr>
</table>
</form>
<?
  }
}
?>
Return current item: Communication Kit