<?php
/* Include Files ***************************/
require_once('../db-config.php');
	if(  defined('LTDVERSION')  ) 
		die('DEMO VERSION!|0');
require_once('../inc/lib-compat-class.php');
require_once('../inc/lib-db-class.php');
require_once('../inc/lib-login-class.php');
/*******************************************/
global $rSdb;

if( ! check_ajax_referer('requestpassword', false) )
	die(__('Security Alert: Direct access not permitted!','recipeshelf').'|0');

$eol	= "\n";
$user	= new userManagement();

$header = 	'From: '. getGenericFROM() .$eol.
			'MIME-Version: 1.0' .$eol.
			'Content-type: text/plain; charset="utf-8"'.$eol;

$msg 	=	__('This email has been sent in response to your lost password request.','recipeshelf') .$eol.
            __('Your new recipeShelf password:','recipeshelf') . ' ';

			
//$_P = cleanGlobals( $_POST );
$user_i = _rem_magic_quote($_POST['user']);

if( $user->checkUser( (string)$user_i ) ){

	$uoptions	= $rSdb->get_option( (string)$user_i."_options" );
	$newPW 		= $user->generatePassword(9,4);

	$msg		.= $newPW.$eol;
	$user->updatePW( (string)$user_i, $newPW );

    @mail( unsanitize($uoptions['rS_email'], true), __('recipeShelf login information','recipeshelf'), $msg, $header );
	echo __('A new password has been sent via email.','recipeshelf') .'<br />'. sprintf(__('Please %slogin%s now.','recipeshelf'),'<a href="index.php">','</a>') . '|1';

} else
    _e('Username not found!','recipeshelf') . '|0';
?>