<?
require_once "configure.php";


if($_POST["btnSubmit"]){
	$newpwd=generate_password(1,$validchar,"U").generate_password(4,$validchar,"N").generate_password(3,$validchar,"L");
	
 	$sql="update `user` set pwd='".md5($newpwd)."' where email='".$_GET["email"]."' ";
	@mysql_query($sql) or die(mysql_error());

	$message="Your new password : $newpwd";

	mail($email,"SGC Forum send you a new password",$message,'From:admin@sgc.com');	
	
		
	print("<script type='text/javascript'>alert('A message has been sent to your email address with password reset instructions.')</script>");
	print("<script type='text/javascript'>location.href='index.php'</script>");

	
}


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=TITLE;?></title>
<link rel="stylesheet" type="text/css" href="style.css" >
<script>
function ValidateForm(theform)
{
	var msg="";

	if(!theform.email.value)msg+="Email is required. \n";
		
	if(msg){
		alert(msg)
		return false;
	}else return true;	
	
}
</script>
</head>

<body class="TextBox">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="46" bgcolor="#38abe3">
  <? require_once "header.php"; ?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><form name="form" method="post" action="<?=$PHP_SELF;?>" ONSUBMIT="return ValidateForm(this)"><table width="60%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td height="35" class="signin">Forgot Password</td>
          </tr>
          <tr>
            <td height="30" bgcolor="#cfecff" class="text">Enter your email</td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text"><input name="email" type="password" class="inputBox" id="email" size="50" /></td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text"><input type="submit" name="btnSubmit" id="btnSubmit" value="Request a New Password" /></td>
          </tr>
        </table>
        </form></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><a href="http://egenos.com" target="_blank">Powered by eGen online solution</a></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
<?
function generate_password ($length, $valid_chars = "",$type)
{

	if($valid_chars=="")
	{
		if($type=="N")$valid_chars = "123456789123456789123456789123456789123456789123456789123456789123456789";
		else if($type=="U")$valid_chars = "ABCDEFGHJKLMNPQRSTUVWXYZABCDEFGHJKLMNPQRSTUVWXYZABCDEFGHJKLMNPQRSTUVWXYZ";
		else $valid_chars = "abcdefghjklmnpqrstuvwxyzabcdefghjklmnpqrstuvwxyzabcdefghjklmnpqrstuvwxyz";
	}

	$password="";
	while($length>0)
	{
		$password.=$valid_chars[rand(0,strlen($valid_chars)-1)];
		$length--;
	}
	return $password;
}

?>