<!--#include file="../conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<%
Dim AdminName,Adminpsd,VeryCode,CIP
AdminName=Trim(Request.Form("adminname"))
Adminpsd=Trim(Request.Form("adminpsd"))
VeryCode=Trim(Request.Form("verycode"))

CIP=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If CIP="" then
   CIP=Request.ServerVariables("REMOTE_ADDR")
End If
opendb
If AdminName="" Or Adminpsd="" Or VeryCode="" Then
   Response.Redirect("admin_login.asp?msg="&Server.URLEncode("请正确填写！"))
   Response.End()
End IF

If VeryCode<>Cstr(session("SafeCode")) Then
   Response.Redirect("admin_login.asp?msg="&Server.URLEncode("验证码错误！"))
   Response.End()
End IF

Call AdminLogin
closedb

Sub AdminLogin
    Dim rs,sql,adminpass
	adminpass=md5(Adminpsd,32)
	set rs= Server.CreateObject("adodb.recordset")
	sql="Select * from "&predb&"Admin where adminname='"&AdminName&"' and adminpsd='"&adminpass&"'"
	rs.open sql,conn,1,3
	If rs.bof And rs.eof Then
	   Response.Redirect("admin_login.asp?msg="&Server.URLEncode("用户名或密码错误！"))
	   Response.End
	Else
	   rs("PreviousIP")=rs("LastIP")
	   rs("PreviousTime")=rs("LastTime")
	   rs("LastIP")=CIP
	   rs("LastTime")=now()
	   rs("LoginSum")=rs("LoginSum")+1
	   rs.update
	   Response.Cookies("adminID")=rs("ID")
	   Response.Cookies("adminname")=AdminName
	   Response.Cookies("adminpass")=adminpass
	   Response.Cookies("adminflag")=rs("AdminFlag")
	   Response.Redirect("admin_index.asp")
	End If
	rs.close
	set rs=nothing
End Sub
%>