<%@language=vbscript codepage=936 %>
<!--#include file="inc/Conn_User.asp"-->
<!--#include file="inc/sip.asp"-->
<!--#include file="inc/md5.asp"-->
<%
dim sql,rs
dim username,password,CookieDate
username=replace(trim(request("username")),"'","")
password=replace(trim(Request("password")),"'","")
CookieDate=trim(request("CookieDate"))
dim ComeUrl
ComeUrl=trim(request("ComeUrl"))
if ComeUrl="" then
	ComeUrl=Request.ServerVariables("HTTP_REFERER")
	if ComeUrl="" then ComeUrl="index.asp" end if
end if
if UserName="" then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>用户名不能为空！</li>"
end if
if Password="" then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>密码不能为空！</li>"
end if
if CookieDate="" then
	CookieDate=0
else
	CookieDate=Clng(CookieDate)
end if
if FoundErr<>True then
	password=md5(password)
	set rs=server.createobject("adodb.recordset")
	sql="select * from " & db_User_Table & " where " & db_User_Name & "='" & username & "' and " & db_User_Password & "='" & password &"'"
	rs.open sql,Conn_User,1,3
	if rs.bof and rs.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>用户名或密码错误！！！</li>"
	else
		if password<>rs(db_User_Password) then
			FoundErr=True
			ErrMsg=ErrMsg & "<br><li>用户名或密码错误！！！</li>"
		else
			if rs(db_User_LockUser)=255 then
				FoundErr=True
				ErrMsg=ErrMsg & "<br><li>对不起，您被管理员锁定，不能登录！</li>"
			else
				rs(db_User_LastLoginIP)=Request.ServerVariables("REMOTE_ADDR")
				rs(db_User_LastLoginTime)=now()
				rs(db_User_LoginTimes)=rs(db_User_LoginTimes)+1
				rs.update
				call SaveCookie_asp163()
				rs.close
				set rs=nothing
				call CloseConn_User()
				response.redirect ComeUrl
			end if
		end if
	end if
	rs.close
	set rs=nothing
end if
if FoundErr=True then
	call WriteErrMsg()
end if
call CloseConn_User()

sub SaveCookie_asp163()
	Response.Cookies("asp163")("UserName")=username
	Response.Cookies("asp163")("Password") = PassWord
	Response.Cookies("asp163")("UserLevel")=rs("UserLevel")
	if UserTableType="Dvbbs6.0" then
		Response.Cookies("aspsky")("username") = username
		Response.Cookies("aspsky")("password") = PassWord
		Response.Cookies("aspsky")("userclass") = rs("userclass")
		Response.Cookies("aspsky")("userid") = rs("userid")
		Response.Cookies("aspsky")("userhidden") = 2
		Response.Cookies("aspsky")("usercookies") = CookieDate
	elseif UserTableType="Dvbbs6.1" then
		Response.Cookies("aspsky")("username") = username
		Response.Cookies("aspsky")("password") = PassWord
		Response.Cookies("aspsky")("userclass") = rs("userclass")
		Response.Cookies("aspsky")("userid") = rs("userid")
		Response.Cookies("aspsky")("userhidden") = 2
		Response.Cookies("aspsky")("usercookies") = CookieDate
	end if
	Response.Cookies("asp163")("CookieDate") = CookieDate
	select case CookieDate
		case 0
			'not save
		case 1
		   	Response.Cookies("asp163").Expires=Date+1
		case 2
			Response.Cookies("asp163").Expires=Date+31
		case 3
			Response.Cookies("asp163").Expires=Date+365
	end select
end sub

'****************************************************
'过程名：WriteErrMsg
'作  用：显示错误提示信息
'参  数：无
'****************************************************
sub WriteErrMsg()
	dim strErr
	strErr=strErr & "<html><head><title>错误信息</title><meta http-equiv='Content-Type' content='text/html; charset=gb2312'>" & vbcrlf
	strErr=strErr & "<link href='style.css' rel='stylesheet' type='text/css'></head><body>" & vbcrlf
	strErr=strErr & "<table cellpadding=6 cellspacing=1 border=0 width=400 align=center bgcolor=cccccc>" & vbcrlf
	strErr=strErr & "  <tr align='center' bgcolor=f2f2f2><td height='22'><strong>错误信息</strong></td></tr>" & vbcrlf
	strErr=strErr & "  <tr bgcolor=ffffff><td height='100' valign='top'><br><b>&nbsp;产生错误的可能原因：</b><br>" & errmsg &"</td></tr>" & vbcrlf
	strErr=strErr & "  <tr align='center'><td bgcolor=f2f2f2><a href=""User_Login.asp?ComeUrl=" & ComeUrl & """ >&lt;&lt; 返回登录页面</a></td></tr>" & vbcrlf
	strErr=strErr & "</table>" & vbcrlf
	strErr=strErr & "</body></html>" & vbcrlf
	response.write strErr
end sub

%>