<?php
/*
 **************************************************************************************************
 *    Copyright (c) 2010-2012 Just Another Video script
 *
 * 	  This file is part of Just Another Video Script.
 *    Version 1.4.3
 *    info@justanothervideoscript.com
 **************************************************************************************************
 *    Come to website for support or buying additional plugins/modules.
 *    http://justanothervideoscript.com/
 **************************************************************************************************
 *    By using this software you agree that you have read and acknowledged our End-User License
 *    Agreement available at http://justanothervideoscript.com/license and can be bound by it.
 **********************************************************************************
 */
 if (isset($_POST['submit'])) {
	$db->query("SELECT * FROM member WHERE LOWER(email) = '".quote_smart(strtolower($_POST['email']))."' LIMIT 1") ;
	if ($db->numRows() != 0) {
		$res = $db->fetch() ;
		$newpass = substr(sha1(uniqid(rand())), -8) ;
		$db->query("UPDATE member SET password = '".sha1($newpass)."' WHERE id = ".$res['id']) ;
		$msg = getEmailformat("email_forgot") ;
		$msg = str_replace("[USERNAME]", $res['username'], $msg) ;
		$msg = str_replace("[PASSWORD]", $newpass, $msg) ;
		$msg = str_replace("[SITENAME]", getSetting("sitename", $db), $msg) ;
		$headers = "From: \"".getSetting('default_from', $db)."\" <".getSetting("contact_email", $db).">>\r\n"."Reply-To: ".getSetting("contact_email", $db)."\r\n"."X-Mailer: PHP/".phpversion() ;
		sendmail(array(array("email"=>$res['email'], "name"=>$res['username'])), 'Password reset', $msg, $headers, 'yes') ;
		$haltMessage = "Email sent." ;
	}
	else {
		$message = "The email address you entered is not recognised!" ;
	}
}
