<!--#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 request.Cookies(sdcms_cookies&"sdcms_name")<>"" and request.Cookies(sdcms_cookies&"sdcms_pwd")<>"" then
response.Redirect("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=gb2312" />
<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=='')
   {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="4" 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
set sdcms=new Sdcms_Function
sdcms.check_post
response.Cookies(sdcms_cookies&"sdcms_ip")=sdcms.getip
username=sdcms.HTMLEncode(trim(request("username")))
password=sdcms.HTMLEncode(trim(request("password")))
code=trim(request.form("yzm"))
getcode=Session("SDCMSCode")
if errnum>=loginnum then echo "系统已禁止您今日再登录":died
if code="" then
echo "<script>alert('验证码不能为空！');location.href='javascript:history.go(-1)';</script>":Died
end if
if code<>"" and not isnumeric(code) then
echo "<script>alert('验证码必须为数字！');location.href='javascript:history.go(-1)';</script>":Died
end if

if code<>getcode then
echo "<script>alert('验证码错误！');location.href='javascript:history.go(-1)';</script>":Died
end if
if username="" or password="" then
echo "用户名或密码不能为空":Died
else
  set rs=conn.execute("select id,sdcms_name,sdcms_pwd,alllever from sd_admin where sdcms_name='"&username&"' and sdcms_pwd='"&md5(password)&"'")
  if rs.eof then
     conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&username&"','"&sdcms.getip&"','登录失败')")
     echo "用户名或密码错误,今日还有 "&loginnum-errnum&" 次机会":Died
  else
	  response.Cookies(sdcms_cookies&"sdcms_id")=rs(0)
	  response.Cookies(sdcms_cookies&"sdcms_name")=username
	  response.Cookies(sdcms_cookies&"sdcms_pwd")=md5(password)
	  if rs(3)<>"" then
	  response.Cookies(sdcms_cookies&"sdcms_all_lever")=rs(3)
	  end if
	  conn.execute("update sd_admin set logintimes=logintimes+1,lastip='"&sdcms.getip&"' where id="&rs(0)&"")
	  conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&username&"','"&sdcms.getip&"','登录成功')")
	  response.Redirect("sdcms_index.asp"):Died
	  '自动删除30天前的Log记录
		conn.execute("Delete from sd_log where DateDiff('d',adddate,now())>30")
    end if
end if
set sdcms=nothing
end sub

sub out
	conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','退出登录')")
	response.Cookies(sdcms_cookies&"sdcms_id")=empty
	response.Cookies(sdcms_cookies&"sdcms_name")=empty
	response.Cookies(sdcms_cookies&"sdcms_pwd")=empty
	response.Cookies(sdcms_cookies&"sdcms_all_lever")=empty
	response.Cookies(sdcms_cookies&"sdcms_ip")=empty
	response.Redirect("?")
end sub

Function errnum
	set sdcms=new Sdcms_Function
		sql="select count(id) from sd_log where ip='"&sdcms.getip&"' and content like '登录失败' and "
		if Is_sql=0 then
			sql=sql&" adddate>=date()"
		else
			sql=sql&" adddate>=getdate()"
		end if
		errnum=conn.execute(sql)(0)
	set sdcms=nothing
end Function
%>