<?php
	session_start(); 
  	require_once('inc/conn.php');
	
	require_once('inc/constant.php');
	$username=inputsafe(trim($_POST['username']));
	$password=inputsafe(trim($_POST['password']));
	$passRetryTimes=8; //最大重试密码次数
	$passdelaytime=1800; //重试间隔时间 30分钟
	$code=$_SESSION["code"];
	
	if(!isset($_SESSION['passTimes']))
	{$_SESSION['passTimes']=0;}

	if(!isset($_SESSION['startTimes']))
	{$_SESSION['startTimes']=0;}

	
?>
<!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>
<title><?=$engineName?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
	<?
	$_SESSION['passTimes']++;

	if($_SESSION['passTimes']>$passRetryTimes)   //超过规定次数进行验证码验证
	{
		if($_SESSION['startTimes']==0){$_SESSION['startTimes']=time();}
		$waittime=$_SESSION['startTimes']+$passdelaytime-time();
		if($waittime>0){ 
			echo "<script>
				alert('错误连续超过".$passRetryTimes."，请".(round($waittime/60))."分钟后再试'); 
				location='index.php';	
			</script>";
			 
		}else{
			$_SESSION['startTimes']=0;  //重置
			$_SESSION['passTimes']=0;
		}
	}
	
		if(strpos($username,"'")!==false || strpos($username,'"')!==false )
		{
			echo 	"<script>
							alert('您的账号和密码不能为空  ！'); 
							location='index.php';	
						</script>";
		}
		
		
		if(empty($username) || empty($password))
		{
			echo 
						"<script>
							alert('您的账号和密码不能为空！'); 
							location='index.php?username=".$username."';	
						</script>";
		}
	  else
	  {
			require_once('inc/conn.php');
			$opendb=new mydb();
			$sqlstr="select * from ls_admin where  adminName='".$username."'";
			
			
			$query1=$opendb->query($sqlstr);
			$rows=mysql_fetch_assoc($query1);
			$myrows=mysql_num_rows($query1); 
			if($myrows==0)
			{
				$_SESSION['retryTimes']++;
				echo "
						
						<script>
							alert('对不起，用户名或密码不正确 ！');
							location='index.php?username=".$username."';	
						</script>
						";
			}
			if(md5($password)!=$rows['adminPwd'] || $username!='admin')
			{
				$_SESSION['retryTimes']++;
				echo "
						<script>
							alert('对不起，用户名或密码不正确！');
							location='index.php?username=".$username."';		
						</script>
						";
			} 
		else
		{
			if($_SESSION['retryTimes']>$codeRetryTimes)   //超过规定次数进行验证码验证
			{
				if($_POST['code']=="")
				{
					echo "<script>
								alert('请输入验证码！'); 
								location='index.php?username=".$username."';	
							</script>";
				}
				if(strtoupper($_POST['code'])!=$_SESSION["code"])
				{
					echo "<script>
								alert('验证码错误！'); 
								location='index.php?username=".$username."';	
							</script>";
				}else{
					$_SESSION['retryTimes']=0;
					$_SESSION['inputTimeOut']=time();
					$_SESSION['username']=$username;
					$_SESSION['passTimes']=0;
					$_SESSION['startTimes']=0;  //重置
					
					//$_SESSION['password']=$password;
					//header("location:all.php");	
					// require_once('../update/updatels.php');  
					echo "	<script>location='all.php';</script>";
				}
			}else{
				$_SESSION['retryTimes']=0;
				$_SESSION['inputTimeOut']=time();
				$_SESSION['username']=$username;
					
				$_SESSION['passTimes']=0;
				$_SESSION['startTimes']=0;  //重置
				//echo  $_SESSION['landir']."--";exit;
					//$_SESSION['password']=$password;
					//header("location:all.php");	
					// require_once('../update/updatels.php');  
					echo "	<script>location='all.php';</script>";
			}
		}
		
	  }
  
?>

<body>
</body>
</html>