<?php
include($setting['sitepath'] . '/includes/config.php');
if (isset($_POST['submit'])) {
	$username = $_POST["username"];
	$res = yasDB_select("select * from user where username='$username'") or die("cannot select from email");				
	$row = $res->fetch_array(MYSQLI_ASSOC);
	$email = $row["email"];
	srand((double)microtime()*1000000);  
	$random = rand(1234,2343); 
	$password = $row["name"].$random; 
	$upassword = md5($password);

	$headers = "From: $eheader \n"; //from address
	$headers .= "MIME-Version: 1.0\n";
	$headers .= "Content-type: text/html; charset=iso-8859-1 \n";
	$subject ="Password Reset - Do Not Reply";

	$body="<div align=center><br><br>----------------------------- Password Reset--------------------------------<br><br><br><br>
	Your New Password is: $password</div>";

	if(@mail($email,$subject,$body,$headers)) {
		yasDB_update("update user set password='$upassword' where username='$username'");
		echo "<font class=tblackb>Your password has been sent to your Email address</font>";} 
	else {
		echo "Unable to send the email. Your password was not reset. Please contact the administrator for assistance.";
	}
}
?>
<div id="left">
	<h1>Reset Password</h1>
	<br/><center>
	<form name="myform" action="templates/<?php echo $setting['theme']?>/forgotpassword.php" method="post">
		Username: <input type="text" name="username" size="15" />
		<input type="submit" name="submit" value="Submit" />
	</form>
	</center>