领星动网编程开发之爆炸小宇宙

cnitblog.com/lxasp - - 有一种信念叫做编程
posts - 61, comments - 34, trackbacks - 0, articles - 0

第一个版本的后台登录代码:

<!--#INCLUDE FILE="conn.asp"-->
<!--#INCLUDE FILE="Core_clsFormBuilder.asp"-->
<!--#INCLUDE FILE="Core_clsValidField.asp"-->
<!--#INCLUDE FILE="Core_clsASPTemplate.asp"-->
<!--#INCLUDE FILE="Core_clsCaller.asp"-->
<!--#INCLUDE FILE="md5.asp"-->
<%
'LoadPage
'
LoadForm

Select Case Request.QueryString("action")

Case "chkadmin"
    
Call CheckForm1ST()
    
Case "checkerr"
    
Call CheckFormERR()

Case ""
    
Call ShowUI()
Case Else
    
Call ShowUI()
    
End Select

'显示验证码
'
GetCode="<img src=""DV_getcode.asp"" alt= ""验证码,看不清楚?请点击刷新验证码"" style=""cursor:pointer;height:20px;"" onclick=""this.src='DV_getcode.asp'"" />"

'检查验证码是否正确
Public Function CodeIsTrue(CodeStr)
    
If CStr(Session("GetCode"))=CStr(CodeStr) And CodeStr<>""  Then
        CodeIsTrue
=True
        Session.Contents.Remove(
"GetCode")
    
Else
        CodeIsTrue
=False
        Session.Contents.Remove(
"GetCode")
    
End If    
End Function


Sub ShowUI()

Dim t,outHTML,f

Set t=LoadPage("Admin_Login")

If Not t Is Nothing Then
    
    t(
"page_title")="领星网站管理系统登录"
    
    f
=LoadForm("Form_AdminLogin","?action=chkadmin",Null,Null)
    
    f
=Replace(f,"{=value_Form_AdminLogin_au_name}","")
    f
=Replace(f,"{=value_Form_AdminLogin_au_pwd}","")
    f
=Replace(f,"{=value_Form_AdminLogin_incode}","")

    f
=Replace(f,"{=Readonly_Form_AdminLogin_au_name}","")
    f
=Replace(f,"{=Readonly_Form_AdminLogin_au_pwd}","")
    f
=Replace(f,"{=Readonly_Form_AdminLogin_incode}","")

    
    t(
"form_admin_login")=f
    
    outHTML
=t.GetOutPut

    Response.Write outHTML
    
    
'AppCa.Remove("TPage_Admin_Login")
    
    
'AppCa.Remove("TForm_Form_AdminLogin")

Else
    Response.Write 
"加载页面模板出错!!!"
End If

End Sub

Sub CheckForm1ST()
    
    
Dim t,o,errs,fd
    
Dim i,l,sii,lid
    
    
On Error Resume Next

'Dim fd_au_name : fd_au_name=Trim(Request.Form("au_name"))
'
Dim fd_au_pwd : fd_au_pwd=Trim(Request.Form("au_pwd"))
'
Dim fd_incode : fd_incode=Trim(Request.Form("incode"))

    
Set t=New clsValidField

    
If t.GetValidateFormDataX(o,fd,"Form_AdminLogin"Then
        
Set t=Nothing
        
'验证表单的数据完全正确则:
        
        
'fd -- Form Data
        Execute fd
        
'Response.Write "<pre>" & fd & "<pre>"
        
        errs
=False
        
        
Set t=LoadPage("PageMsgBox")
        
        t(
"page_title")="登录失败"
        t(
"def_time")=" "
        t(
"def_link")=" "
        
        t(
"msg_title")="错误"
        
        t(
"btn_link")="Admin_Login.asp"
        t(
"btn_text")="返回登录页面"
        t.Add 
"btn_item"

        
If Not CodeIsTrue(fd_incode) Then
            t(
"msg_text")="你输入的验证码不正确"
            t.Add 
"msg_item"
            errs
=True
        
Else
            
            fd_au_name
=Replace(fd_au_name,"'","''")
            fd_au_pwd
=md5(fd_au_pwd)
            
            SQL 
= "SELECT au_Name,au_Rgt,au_LogCurTime,au_LogCurIP,au_LogLstTime,au_LogLstIP FROM Admin_User WHERE au_name='"&fd_au_name&"' AND au_pwd='"&fd_au_pwd&"'"
            
Set rs=Server.CreateObject("ADODB.Recordset")
            rs.Open SQL,conn,
1,3 '11 for Read '13 for Write
            sqlcount=sqlcount+1
            
If rs.EOF And rs.BOF Then
                t(
"msg_text")="系统中找不到匹配的用户名或密码"
                t.Add 
"msg_item"
                errs
=True
            
Else
                rs.MoveFirst
                
                Session(CookieName
&"_au_Name")=rs("au_Name")
                Session(CookieName
&"_au_Rgt")=rs("au_Rgt")
                
                rs(
"au_LogLstIP")=rs("au_LogCurIP")
                rs(
"au_LogLstTime")=rs("au_LogCurTime")
                
                rs(
"au_LogCurIP")=Request.ServerVariables("REMOTE_ADDR")
                rs(
"au_LogCurTime")=Now()
                
                rs.Update
            
End If
            rs.Close
            
Set rs = Nothing
            
If Err Then
                t(
"msg_text")=Err.Description
                t.Add 
"msg_item"
                errs
=True
            
End If
            
        
End If
        
        
If errs Then
            
'将错误信息传到Session变量中去,用于传递到另外一个页面
            Session(CookieName&"_FormValidErr")=t.GetOutPut
            
'为了防止用户刷新,出现错误后立即跳转到显示错误信息的页面
            Response.Redirect "?action=checkerr"
        
Else
            
Set t=Nothing
            
Set t=LoadPage("PageMsgBox")
            
            t(
"page_title")="进入管理"
            t(
"def_time")=" "
            t(
"def_link")=" "
            
            t(
"btn_link")="javascript:window.top.location.replace('Admin_Frameset.asp');"
            t(
"btn_text")="进入网站管理"
            t.Add 
"btn_item"
        
            t(
"msg_title")="成功"
        
            t(
"msg_text")="<script language=""JavaScript"" type=""text/javascript"">window.top.location.replace('Admin_Frameset.asp');</script>"
            t.Add 
"msg_item"
        
            Response.Write t.GetOutPut
        
End If
        
    
Else
        
Set t=Nothing
        
'验证表单的数据出现错误则:
        '收集错误信息到 errs
        Set t=LoadPage("PageMsgBox")
        
        t(
"page_title")="登录失败"
        t(
"def_time")=" "
        t(
"def_link")=" "
        
        t(
"msg_title")="错误"
        
        t(
"btn_link")="Admin_Login.asp"
        t(
"btn_text")="返回登录页面"
        t.Add 
"btn_item"
        
        
If IsArray(o) Then
            l
=UBound(o,2)
            
For i=0 To l
                
If o(1,i)=False Then
                    t(
"msg_text")=""&o(2,i)&":"&o(3,i)&"<br />"&o(4,i)&""
                    t.Add 
"msg_item"
                
End If
            
Next
        
End If
        
'将错误信息传到Session变量中去,用于传递到另外一个页面
        Session(CookieName&"_FormValidErr")=t.GetOutPut
        
'为了防止用户刷新,出现错误后立即跳转到显示错误信息的页面
        Response.Redirect "?action=checkerr"
    
End If
    
End Sub

Sub CheckFormERR()
    
    
Dim o
    
    
'当表单的数据有错误时,从Session变量中取出错误提示信息并输出
    o=Session(CookieName&"_FormValidErr")
    
'数据已经取出,立即清空释放Session变量的内存资源
    Session(CookieName&"_FormValidErr")=Empty
    
If Len(o)=0 Then
        Response.Write 
"请勿刷新本页!"
    
Else

        Session(CookieName
&"_au_Name")=Empty
        Session(CookieName
&"_au_Rgt")=Empty

        Response.Write o
    
End If
    
End Sub

%
>


第二个版本的后台登录代码:

 

<!--#INCLUDE FILE="conn.asp"-->
<!--#INCLUDE FILE="SYS/Core_clsLxxTPL.asp"-->
<!--#INCLUDE FILE="SYS/Core_clsGIListSHTM.asp"-->
<!--#INCLUDE FILE="SYS/Core_clsStrConcat.asp"-->
<!--#INCLUDE FILE="SYS/Core_ClassCaller.asp"-->
<!--#INCLUDE FILE="SYS/Incl_FuLib.asp"-->
<!--#INCLUDE FILE="SYS/Appm_clsUserSession.asp"-->
<!--#INCLUDE FILE="SYS/Appm_clsLogAction.asp"-->
<!--#INCLUDE FILE="SYS/Nome_md5.asp"-->
<%

Dim gourl,tpl
gourl
=Request.QueryString("go")

Dim usr,olog

Set usr=New clsUserSession
Set olog=New clsLogAction

usr.IsAdmin
=True
usr.IsCookie
=False

oLog.IsAdmin
=True
oLog.IsCookie
=False

If gourl<>"login" And gourl<>"chklogin" Then
    
If Not usr.Exists Then
        usr.Clear
        Response.Redirect 
"admin.asp?go=login"
    
End If
End If

Select Case gourl
    
Case "login"
    
Set tpl=LoadPage("Admin_Login")
    tpl(
"formaction")="?go=chklogin"
    Response.Write tpl.Text
    Application.Contents.RemoveAll
    
Case "chklogin"
    usr.Clear
    usr.Name
=Request.Form("ua_name")
    usr.Password
=Request.Form("ua_pwd")
    usr.ValidCode
=Request.Form("incode")
    usr.Login()
    
If usr.HasErr Then
        oLog(
"登录","后台")="用户[" & Request.Form("ua_name"& "]登录后台失败:"&usr.GetErr
        ErrBoxGo usr.GetErr,
"?go=login"
        usr.ErrClear
    
Else
        oLog(
"登录","后台")="用户[" & Request.Form("ua_name"& "]登录后台成功"
        MsgBox1 
"<script type='text/javascript'>window.top.location.replace('?go=frameset');</script>","javascript:window.top.location.replace('?go=frameset');"
    
End If
    
Case "frameset"
    
Set tpl=LoadPage("Admin_Frameset")
    Response.Write tpl.Text
    
Case "frametop"
    
Set tpl=LoadPage("Admin_FrameTop")
    tpl(
"ua_name")=usr.Name
    tpl(
"ua_gname")=usr.GroupName
    Response.Write tpl.Text
    
Case "frameleft"
%
><!--#INCLUDE FILE="SYS/admin/frameleft.asp"--><%

Case "framemain"
%
><!--#INCLUDE FILE="SYS/admin/framemain.asp"--><%

Case "logout"
    oLog(
"退出","后台")="用户[" & usr.Name & "]退出后台"
    usr.Clear
    Response.Redirect 
"admin.asp?go=login"

Case Else
    
If usr.Exists Then
        
Set tpl=LoadPage("Admin_Frameset")
        Response.Write tpl.Text
    
End If
End Select

Application.Contents.RemoveAll

'Response.Write FormatNumber((Timer-startime)*1000,3)

%
>

第二版的用户登录的类:

<%
Class clsUserSession
    
    
Public IsCookie

    
Private Cookie
    
    
Private m_name,m_pwd,m_vcode,m_admin,m_timeout
    
    
Private ErrMsg,bHasErr

    
Private Sub Class_Initialize()
        IsCookie
=False
        m_admin
="_member"
        
Set Cookie=New clsCookie
    
End Sub
    
Private Sub Class_Terminate()
        
Set Cookie=Nothing
    
End Sub

    
Private Sub AddErr(s)
        ErrMsg
=ErrMsg&"用户会话出错信息 - "&s&HTML_BR
        bHasErr
=True
    
End Sub
    
Public Function GetErr()
        GetErr
=ErrMsg
    
End Function
    
Public Sub ErrClear()
        ErrMsg
=""
        bHasErr
=False
    
End Sub
    
Public Property Get HasErr()
        HasErr
=bHasErr
    
End Property


    
Public Property Let Name(s)
        m_name
=Replace(s,"'","''")
    
End Property
    
Public Property Get Name()
        
If IsCookie Then
            m_name
=Cookie(CookieName&m_admin&"_name")
        
Else
            m_name
=Session(CookieName&m_admin&"_name")
        
End If
        Name
=m_name
    
End Property

    
Public Property Let Password(s)
        
On Error Resume Next
        m_pwd
=md5(s)
        
If Err Then m_pwd=s
    
End Property

    
Public Property Let ValidCode(s)
        m_vcode
=s
    
End Property

    
Public Property Get GroupID()
        
Dim r
        
If IsCookie Then
            r
=Cookie(CookieName&m_admin&"_gid")
        
Else
            r
=Session(CookieName&m_admin&"_gid")
        
End If
        GroupID
=r
    
End Property

    
Public Property Get GroupName()
        
Dim r
        
If IsCookie Then
            r
=Cookie(CookieName&m_admin&"_gname")
        
Else
            r
=Session(CookieName&m_admin&"_gname")
        
End If
        GroupName
=r
    
End Property

    
Public Property Get UserID()
        
Dim r
        
If IsCookie Then
            r
=Cookie(CookieName&m_admin&"_id")
        
Else
            r
=Session(CookieName&m_admin&"_id")
        
End If
        UserID
=r
    
End Property

    
Public Property Get UserType()
        
Dim r
        
If IsCookie Then
            r
=Cookie(CookieName&m_admin&"_id")
        
Else
            r
=Session(CookieName&m_admin&"_id")
        
End If
        UserType
=r
    
End Property


    
Public Sub SetTimeout(s,IsMin)
        
If s=0 Then
            m_timeout
=""
            
Exit Sub
        
End If
        
If IsMin Then
            m_timeout
="DateAdd(""n""," & s & ",Now)"
        
Else
            m_timeout
="DateAdd(""d""," & s & ",Now)"
        
End If
    
End Sub

    
Public Property Let IsAdmin(s)
        
If s Then
            m_admin
="_admin"
        
Else
            m_admin
="_member"
        
End If
    
End Property
    
Public Property Get IsAdmin()
        
If m_admin="_admin" Then
            IsAdmin
=True
        
Else
            IsAdmin
=False
        
End If
    
End Property


    
Private Function CodeIsTrue(CodeStr)
        
If CStr(Session("GetCode"))=CStr(CodeStr) And CodeStr<>""  Then
            CodeIsTrue
=True
            Session.Contents.Remove(
"GetCode")
        
Else
            CodeIsTrue
=False
            Session.Contents.Remove(
"GetCode")
        
End If    
    
End Function
    
    
    
Public Function Exists()
        
If IsCookie Then
            Exists
=Cookie.Exists(CookieName&m_admin&"_name")
        
Else
            Exists
=(Len(Session(CookieName&m_admin&"_name"))>0)
        
End If
    
End Function

    
Public Sub Login()
        
        
Dim rgts,tmp,i
        
        
'用户开始尝试登录
        
        
On Error Resume Next
        
        rgts
=""
        
        
If Not CodeIsTrue(m_vcode) Then
            AddErr 
"验证编码不正确"
            
Exit Sub
        
End If
        
        
If IsAdmin Then
            SQL 
= "SELECT " & Zua_bid_ & "," & Zua_name_ & "," & Zua_gid_ & "," & Zug_name_ & "," & Zua_type_ & _
                        
"," & Zug_rgtsee_ & "," & Zug_rgtfnd_ & "," & Zug_rgtadd_ & "," & Zug_rgtmod_ & "," & Zug_rgtdel_ & "," & Zug_rgtbuy_ & "," & Zug_rgtdwn_ & "," & Zug_rgtsay_ & "," & Zug_rgtmix_ & _
                        
" FROM " & dbt_UA & "," & dbt_UG & " WHERE " & Zua_gid_ & "=" & Zug_id_ & " AND " & Zua_name_ & "='" & m_name & "' AND " & Zua_pwd_ & "='" & m_pwd & "'"
        
End If

        
Set rs=Server.CreateObject("ADODB.Recordset")
        rs.Open SQL,conn,
1,1 '11 for Read '13 for Write
        sqlcount=sqlcount+1
        
If rs.EOF And rs.BOF Then
            AddErr 
"管理员名或密码不正确"
        
Else
            rs.MoveFirst

            
For i=0 To 8
                
If Not IsNull(rs(5+i)) Then tmp=rs(5+i)
                rgts
=rgts&tmp&"|"
            
Next

            
If IsCookie Then
                Cookie(CookieName
&m_admin&"_id")=rs(0)
                Cookie(CookieName
&m_admin&"_name")=rs(1)
                Cookie(CookieName
&m_admin&"_gid")=rs(2)
                Cookie(CookieName
&m_admin&"_gname")=rs(3)
                Cookie(CookieName
&m_admin&"_type")=rs(4)
                Cookie(CookieName
&m_admin&"_rgts")=rgts
                
                
If Len(m_timeout)>0 Then
                    Cookie(CookieName
&m_admin&"_id").Expires=Eval(m_timeout)
                    Cookie(CookieName
&m_admin&"_name").Expires=Eval(m_timeout)
                    Cookie(CookieName
&m_admin&"_gid").Expires=Eval(m_timeout)
                    Cookie(CookieName
&m_admin&"_gname").Expires=Eval(m_timeout)
                    Cookie(CookieName
&m_admin&"_type").Expires=Eval(m_timeout)
                    Cookie(CookieName
&m_admin&"_rgts").Expires=Eval(m_timeout)
                
End If
            
Else
                Session(CookieName
&m_admin&"_id")=rs(0)
                Session(CookieName
&m_admin&"_name")=rs(1)
                Session(CookieName
&m_admin&"_gid")=rs(2)
                Session(CookieName
&m_admin&"_gname")=rs(3)
                Session(CookieName
&m_admin&"_type")=rs(4)
                Session(CookieName
&m_admin&"_rgts")=rgts
            
End If

        
End If
        rs.Close
        
Set rs = Nothing
        
        
If Err Then
            AddErr Err.Description
        
End If
        
    
End Sub
    
    
Public Sub Clear()
        Cookie.Remove(CookieName
&m_admin&"_id")
        Cookie.Remove(CookieName
&m_admin&"_name")
        Cookie.Remove(CookieName
&m_admin&"_gid")
        Cookie.Remove(CookieName
&m_admin&"_gname")
        Cookie.Remove(CookieName
&m_admin&"_type")
        Cookie.Remove(CookieName
&m_admin&"_rgts")
        
        Session.Contents.Remove(CookieName
&m_admin&"_id")
        Session.Contents.Remove(CookieName
&m_admin&"_name")
        Session.Contents.Remove(CookieName
&m_admin&"_gid")
        Session.Contents.Remove(CookieName
&m_admin&"_gname")
        Session.Contents.Remove(CookieName
&m_admin&"_type")
        Session.Contents.Remove(CookieName
&m_admin&"_rgts")
    
End Sub

End Class
%
>


 

________________________________________________________________________________________________

再贴一个菜鸟入门的ASP的登录代码(不是我写的):

 

<%@ Language=VBScript %>
<!--#include file="..\inc\conn.asp"-->
<%
if request.Form("submit")<>"" then
    
if request.Form("userid")="" or request.Form("password")="" then
        response.Write(
"<script language=javascript>alert('用户名或者密码不能为空!');history.back();</script>")
        response.end
    
end if
    
    
set rs=conn.execute("select * from gly where uid='"&trim(request.form("userid"))&"' and pwd='"&trim(request.form("password"))&"'")
    
if rs.eof then
        response.Write(
"<script language=javascript>alert('用户名或者密码验证失败!');history.back();</script>")
        response.End()
    
else
        
if rs("IsSuper")=1 then
            session(strSession
&"uid")="s"
            session(strSession
&"uidn")=rs("id")
        
else
            session(strSession
&"uid")="n"
            session(strSession
&"uidn")=rs("id")
        
end if
        response.Redirect(
"index.asp")
        response.End()
    
end if
    rs.close
    
set rs=nothing
end if
%>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
body
{font-size: 12px;}
td
{font-size: 12px;}
input
{font-size: 12px;}
select
{font-size: 12px;}
.style6 
{color: #993300; font-weight: bold; font-size: 12px; }
.style7 
{color: #666666}
.style9 
{color: #FF0000}
.STYLE11 
{
    font-size
: 14px;
    font-weight
: bold;
}
-->
</style>
<p>&nbsp;</p>
<table width="400" height="300" border="0" align="center" cellpadding="0" cellspacing="0" background="images/login.gif">
  
<tr>
    
<td align="center" valign="middle"><table width="200" border="0" cellspacing="0" cellpadding="0">
<form action="login.asp" name="login" id="login" method="post">
      
<tr>
        
<td width="60" height="30" align="center"><span class="STYLE11">用户名</span></td>
        
<td align="center"><input name="userid" type="text" id="userid" style="width:120px;"/></td>
      
</tr>
      
<tr>
        
<td width="60" height="30" align="center"><span class="STYLE11">密 码</span></td>
        
<td align="center"><input name="password" type="password" id="password"  style="width:120px;" /></td>
      
</tr>
      
<tr>
        
<td height="30" colspan="2" align="center"><label>
          
<input type="submit" name="Submit" value=" 提 交 " />
        
</label></td>
        
</tr>
</form>
    
</table></td>
  
</tr>
</table>


 

 

只有注册用户登录后才能发表评论。