<% Option Explicit %>
<!--#include file="../Inc/Cls_DB.asp" -->
<!--#include file="../Inc/Const.asp" -->
<!--#include file="../Inc/Md5.asp" -->
<!--#include file="../Inc/Enpas.asp" -->
<%
Set DBC = New DataBaseClass
Set Conn = DBC.OpenConnection()
Set DBC = Nothing
'==============================================================================
'软件名称：风讯网站信息管理系统
'当前版本：Foosun Content Manager System V2.0
'最新更新：2005.01
'==============================================================================
'商业注册联系：028-85098980-601,602 技术支持：028-85098980-606、607,客户支持：608
'产品咨询QQ：159410,655071,66252421
'技术支持:所有程序使用问题，请提问到bbs.foosun.net我们将及时回答您
'程序开发：风讯开发组 & 风讯插件开发组
'论坛支持：风讯在线论坛(http://bbs.foosun.net)
'官方网站：www.Foosun.net  演示站点：test.cooin.com    
'网站建设专区：www.cooin.com
'==============================================================================
'免费版本请在新闻首页保留版权信息，并做上本站LOGO友情连接
'==============================================================================
Dim DBC,Conn,RsLoginObj,RsLogObj
Dim UserName,UserPass,VerifyCode,System,SqlLog,SqlLogin,Url
if Request("UrlAddress")<>"" then
	Url = Request("UrlAddress")
else
	if request.form("LoginType")="1" then
		Url = "Main_News.asp"
	elseif request.form("LoginType")="2" then
		Url = "Main.asp"
	else
		Url = "Main_News.asp"
	end if
end if
UserName = Replace(Trim(Request.Form("Name")),"'","''")
UserPass = Md5(Replace(Trim(Request.Form("Password")),"'","''"),16)
VerifyCode = Replace(Trim(Request("VerifyCode")),"'","")

if UserName = "" or  UserPass = "" then
	Response.Write("<script>alert(""错误：\n请填写完整"&Copyright&""");location.href=""Login.asp"";</script>")
	Response.End
end if

if  VerifyCode <> CStr(Session("GetCode"))  then 
	Response.Write("<script>alert(""错误：\n验证码错误"&Copyright&""");location.href=""Login.asp"";</script>")
	Response.End
end if
if request("VerifyCode") = "" then
	Response.Write("<script>alert(""错误：\n请填写验证码"&Copyright&""");location.href=""Login.asp"";</script>")
	Response.End
elseif Session("GetCode") = "9999" then
	Session("GetCode")=""
elseif Session("GetCode") = "" then
	Response.Write("<script>alert(""错误：\n请不要重复提交，如需重新登录请返回登录页面。\n返回后请刷新登录页面后重新输入正确的信息"&Copyright&""");location.href=""Login.asp"";</script>")
	Response.End
elseif cstr(Session("GetCode"))<>cstr(Trim(Request("VerifyCode"))) then
	Response.Write("<script>alert(""错误：\n您输入的确认码和系统产生的不一致，请重新输入。\n返回后请刷新登录页面后重新输入正确的信息"&Copyright&""");location.href=""Login.asp"";</script>")
	Response.End
end if
Session("GetCode")=""
System = Request.ServerVariables("HTTP_USER_AGENT")
if Instr(System,"Windows NT 5.2") then
	System = "Win2003"
elseif Instr(System,"Windows NT 5.0") then
	System="Win2000"
elseif Instr(System,"Windows NT 5.1") then
	System = "WinXP"
elseif Instr(System,"Windows NT") then
	System = "WinNT"
elseif Instr(System,"Windows 9") then
	System = "Win9x"
elseif Instr(System,"unix") or instr(System,"linux") or instr(System,"SunOS") or instr(System,"BSD") then
	System = "类Unix"
elseif Instr(System,"Mac") then
	System = "Mac"
else
	System = "Other"
end if

Set RsLoginObj = server.CreateObject ("ADODB.RecordSet")
SqlLogin = "select * from admin where Name='"&UserName&"' and  password='"&UserPass&"'"
RsLoginObj.Open SqlLogin,Conn,1,1
if Not RsLoginObj.EOF then
	if cint(RsLoginObj("Lock")) = 1 then
		Response.Write("<script>alert(""错误:\n您已经被锁定,请与管理联系\n"&Copyright&""");window.close();</script>")
		Response.End
	end if
	dim RscsObj,GoRefresh
	Session("Name") = RsLoginObj("name")
	Session("PassWord") = RsLoginObj("PassWord")
	Session("AdminID") = RsLoginObj("ID")
	Set RsLogObj = Server.Createobject("adodb.recordset")
	SqlLog = "Select * from Log"
	RsLogObj.open SqlLog,Conn,3,3
	RsLogObj.addnew
	RsLogObj("LogUser") = UserName
	RsLogObj("LogIP") = request.ServerVariables("Remote_Addr")
	RsLogObj("OS") = System
	RsLogObj("Result") = 1
	RsLogObj("LoginTime") = now()
	RsLogObj.update
	RsLogObj.close
	set RsLogObj = Nothing
	If CBool(Request.Form("AutoGet")) or Request.Form("AutoGet")<>"" Then
        Response.Cookies("FoosunCookie")("AdminName")=Session("Name")
        Response.Cookies("FoosunCookie").Expires=Date()+365
    Else
        Response.Cookies("FoosunCookie")("AdminName")=""
        Response.Cookies("FoosunCookie").Expires=Date()-1
    End If
   	Response.Redirect(Url) 
	Response.End
else
	set RsLogObj = Server.Createobject("adodb.recordset")
	SqlLog = "Select * from Log"
	RsLogObj.open SqlLog,Conn,3,3
	RsLogObj.AddNew
	RsLogObj("LogUser") = Request.Form("Name")
	RsLogObj("LogIP") = request.ServerVariables("Remote_Addr")
	RsLogObj("OS") = System
	RsLogObj("ErrorPas") = Request.Form("Password")
	RsLogObj("Result") = 0
	RsLogObj("LoginTime") = Now()
	RsLogObj.update
	RsLogObj.close
	set RsLogObj = Nothing
	Response.Write("<script>alert(""错误:\n请检查用户名和密码的正确性\n"&Copyright&""");location.href=""Login.asp"";</script>")
	Response.End
end if
set Conn = Nothing
Set RsLoginObj = Nothing
%>