<?
include_once("../inc/config.php");
include_once("../inc/publicfun.php");
include_once("../inc/ftbbsdbclass.php");
include_once("../conn.php");
include_once("../inc/checkpost.php");

$username=ftbbs_request(trim($_POST["username"]));
$password=ftbbs_request(trim($_POST["password"]));
$password=md5($password);
$codestr=trim($_POST["codestr"]);

if (CheckName($username)==false){
   ftbbs_msg("用户名不合法!","../admin.php");
   exit;
}
If ($_SESSION["code"]!=$codestr && $_SESSION["errorcount"]>=3){
   ftbbs_msg("验证码错误!","../admin.php");
   exit;
}

$sql="select * from {$tablepre}ftbbs_admin where admin_user='".$username."'";
$rs=mysql_query($sql);
$row = mysql_fetch_array($rs);
$rsnum= mysql_num_rows($rs);
if ($rsnum==0){
   ftbbs_msg("用户名不正确！","../admin.php");
}
else{
      $admin_user=$row["admin_user"];
	  $admin_pwd=$row["admin_pwd"];
	  $admin_qs=$row["adminqs"];
	  $qs=$row["qs"];
	  if ($admin_pwd==$password && $admin_user==$username){
	    $_SESSION["admin_user"]=$admin_user;
	    $_SESSION["admin_pwd"]=$admin_pwd;
	    $_SESSION["admin_qs"]=$admin_qs;
	    $_SESSION["qs"]=$qs;
		$_SESSION["errorcount"]=0;
        header("Location:ftbbs_admin_index.php");
	  }
	  else{
	    $_SESSION["errorcount"]=$_SESSION["errorcount"]+1;
        echo "<script langugae=javascript>alert('你的密码不正确！');";
        echo "window.location.href='../admin.php';</script>";
        exit;
	  }
}
$db->close(); 
?>