<!--#include file="sdcms_check.asp"-->
<%
Const loginnum=3 '登录失败后，禁止的登录的次数（不建议改为很大数字）
Select Case action
	Case "check":check
	Case "out":out
	Case Else:main
End Select
Closedb
Sub main()
	IF Load_Cookies("sdcms_name")<>"" And Load_Cookies("sdcms_pwd")<>"" Then
	'Return("sdcms_index.asp"):Died
End IF
%>
<!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>
<link href="images/home.css" rel="stylesheet" type="text/css" />
</head>
<body>
<Script>if(self!=top){top.location=self.location;}</script>
<div class="b_w">
   <div class="l_t">
      <div class="left l_title">网站管理系统</div>
	  <div class="right"><a href="../"><img src="images/icon_back.gif" alt="返回" hspace="4" vspace="8" border="0"  /></a><a href="javascript:window.close()"><img src="images/icon_close.gif" alt="关闭" hspace="4" vspace="8" border="0"/></a></div>
   </div>
  <div class="l_bg">
    <ul class="l_user">
<script language="javascript">
function checklogin()
{
  if(document.login.username.value=='')
     {alert('请输入帐户');
      document.login.username.focus();
      return false
    }
  if (document.login.password.value=='')
   {alert('请输入密码');
    document.login.password.focus();
    return false
   }
   //if (document.login.yzm.value=='')
  if (1==2)
   {alert('请输入验证码');
    document.login.yzm.focus();
    return false
   }
}
</script>
<form action="index.asp?action=check" name="login" method="post" onSubmit="return checklogin();">
	  <li>帐户：<input name="username" size="14" type="text" class="l_input" /></li>
	  <li>密码：<input name="password" size="14" type="password" class="l_input" /></li>
	  <li>验证：<input name="yzm" size="3" type="text" class="l_input" /> <img src="../inc/sdcmscode.asp?t0=60&t1=14" align="absmiddle" title="看不清楚?请点击刷新验证码" style=cursor:pointer onClick="this.src+='&'+Math.random();"></li>
	  <li><input class="l_bnt" value="登 录" type="submit" />　<input class="l_bnt" value="重 写" type="reset" /></li>
	  </form>
	</ul>
  </div>
  <div class="l_f">
    <div class="left"><img src="images/f_l.gif" /></div>
	<div class="left"><img src="images/f_bg.gif" width="378" height="36"/></div>
	<div class="right"><img src="images/f_r.gif" /></div>
  </div>
</div>

</body>
</html>
<%
End Sub
Sub Check
Check_post
Add_Cookies "sdcms_ip",Getip
username=HTMLEncode(trim(request("username")))
password=HTMLEncode(trim(request("password")))
code=trim(request.form("yzm"))
getcode=Session("SDCMSCode")
IF errnum>=loginnum Then Echo "系统已禁止您今日再登录":died
'IF code="" Then Alert "验证码不能为空！","javascript:history.go(-1)":Died
'IF code<>"" And Not Isnumeric(code) Then Alert "验证码必须为数字！","javascript:history.go(-1)":Died
'IF code<>getcode Then Alert "验证码错误！","javascript:history.go(-1)":Died
IF username="" or password="" Then
	Echo "用户名或密码不能为空":Died
Else
	Set Rs=conn.execute("select id,sdcms_name,sdcms_pwd,logintimes from sd_admin where sdcms_name='"&username&"' and sdcms_pwd='"&md5(password)&"'")
	IF Rs.Eof Then
		AddLog username,GetIp,"登录失败",1
		Echo "用户名或密码错误,今日还有 "&loginnum-errnum&" 次机会":Died
	Else
		Add_Cookies "sdcms_id",rs(0):Add_Cookies "sdcms_name",username:Add_Cookies "sdcms_pwd",md5(rs(2)&(rs(3)+1))
		Conn.Execute("update sd_admin set logintimes=logintimes+1,lastip='"&GetIp&"' where id="&rs(0)&"")
		AddLog username,GetIp,"登录成功",1
		Return("sdcms_index.asp"):Died
		'自动删除30天前的Log记录
		Conn.Execute("Delete from sd_log where DateDiff('d',adddate,now())>30")
	End IF
End IF
End Sub

Sub Out
	AddLog sdcms_adminname,sdcms_adminip,"退出登录",1
	Add_Cookies "sdcms_id",Empty:Add_Cookies "sdcms_name",Empty:Add_Cookies "sdcms_pwd",Empty:Add_Cookies "sdcms_ip",Empty
	Return("?")
End Sub

Function errnum
	Sql="select count(id) from sd_log where ip='"&GetIp&"' and content like '登录失败' and "
	IF Is_Sql Then
		Sql=Sql&" adddate>=date()"
	Else
		Sql=Sql&" adddate>=getdate()"
	End IF
	Errnum=Conn.Execute(Sql)(0)
End Function
%>