Location: PHPKode > projects > ProjectPress > projectpress/forgot.php
<?php 
session_start(); //Starts the session.
define('access',true);
include('config.inc.php');
include(PM_DIR . 'pm-includes/global.inc.php');
require(PM_DIR . 'pm-includes/functions.php');
if($_SESSION['logged'] == 1) //User is already logged in.
	pm_redirect(PM_URI . '/index.php'); //Goes to main page.




/******************* ACTIVATION BY FORM**************************/
if ($_POST['doReset']=='Reset') {
$err = array();
$msg = array();

foreach($_POST as $key => $value) {
	$data[$key] = pmdb::connect()->escape($value);
}
if(!is_valid_email($data['email'])) {
$err[] = "ERROR - Please enter a valid email"; 
}

$email = $data['email'];

//check if activ code and user is valid as precaution
$rs_check = pmdb::connect()->query("SELECT user_id FROM " . DB . "members WHERE email='$email'"); 
$num = $rs_check->num_rows;
  // Match row found with more than 1 results  - the user is authenticated. 
    if ( $num <= 0 ) { 
	$err[] = "Error - Sorry no such account exists or registered.";
	//header("Location: forgot.php?msg=$msg");
	//exit();
	}


if(empty($err)) {

$new_pwd = generate_user_password();
$pwd_reset = md5($new_pwd);

$rs_activ = pmdb::connect()->query("UPDATE " . DB . "members SET password='$pwd_reset' WHERE 
						 email='$email'");
						 
$host  = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);						 
						 
//send email

$message = 
"Here are your new password details ...\n
User Email: $email \n
Passwd: $new_pwd \n

Thank You

Administrator
$host_upper
______________________________________________________
THIS IS AN AUTOMATED RESPONSE. 
***DO NOT RESPOND TO THIS EMAIL****
";

	$headers  = "From: \"ProjectPress Member Registration\" <auto-reply@$host>\r\n";
	$headers .= "X-Mailer: PHP/" . phpversion();
	
	pm_mail($email,"Reset Password",$message,$headers);					 
						 
$msg[] = "Your account password has been reset and a new password has been sent to your email address.";						 
						 
//$msg = urlencode();
//header("Location: forgot.php?msg=$msg");						 
//exit();
 }
}
?>
<html>
<head>
<title>Forgot Password</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="<?php echo PM_URI ?>/css/login-style.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript" src="<?php echo PM_URI; ?>/js/jquery-1.3.2.min.js"></script>
<script language="JavaScript" type="text/javascript" src="<?php echo PM_URI; ?>/js/jquery.validate.js"></script>
  <script>
  $(document).ready(function(){
    $("#actForm").validate();
  });
  </script>
</head>

<body>
<div id="register">
<table width="100%" border="0" cellspacing="0" cellpadding="5" class="main">
  <tr> 
    <td colspan="3">&nbsp;</td>
  </tr>
  <tr> 
    <td width="160" valign="top"><p>&nbsp;</p>
      <p>&nbsp; </p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p></td>
    <td width="732" valign="top">
<h3 class="titlehdr">Forgot Password</h3>

      <p> 
        <?php
	  /******************** ERROR MESSAGES*************************************************
	  This code is to show error messages 
	  **************************************************************************/
	if(!empty($err))  {
	   echo "<div class=\"msg\">";
	  foreach ($err as $e) {
	    echo "* $e <br>";
	    }
	  echo "</div>";	
	   }
	   if(!empty($msg))  {
	    echo "<div class=\"msg\">" . $msg[0] . "</div>";

	   }
	  /******************************* END ********************************/	  
	  ?>
      </p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>If you have forgot the account password, you can <strong>reset password</strong> 
        and a new password will be sent to your email address.</p>
	 
      <form action="forgot.php" method="post" name="actForm" id="actForm" >
        <table width="65%" border="0" cellpadding="4" cellspacing="4" class="loginform">
          <tr> 
            <td colspan="2">&nbsp;</td>
          </tr>
          <tr> 
            <td width="36%">Your Email</td>
            <td width="64%"><input name="email" type="text" class="required email" id="txtboxn" size="25"></td>
          </tr>
          <tr> 
            <td colspan="2"> <div align="center"> 
                <p> 
                  <input name="doReset" type="submit" id="sub_button" value="Reset">
                </p>
              </div></td>
          </tr>
        </table>
        <div align="center"></div>
        <p align="center">&nbsp; </p>
      </form>
	  
      <p>&nbsp;</p>
	   
      <p align="left">&nbsp; </p></td>
    <td width="196" valign="top">&nbsp;</td>
  </tr>
  <tr> 
    <td colspan="3">&nbsp;</td>
  </tr>
</table>
</div>

<p>&nbsp;</p>
<p><a href="register.php">Register</a> | <a href="login.php">Login</a></p></p>

</body>
</html>
Return current item: ProjectPress