日期:2010-05-01  浏览次数:20929 次

  我们在制作网站时通常想设置用户登陆系统,也就是说当用户登陆之后可以看到相应的内容,这种方法被经常使用了,具体的实现的流程图:

  具体ASP源代码如下:(包括3个文件)

  login.asp

<%@ Language="vbscript" %>
<% Option Explicit %>
<% Response.Buffer = True %>
<!--#include file="dbConn.asp"-->
<%
'================================================
' Was the form submitted?
' If so, lets check the Username and Password
'================================================
If Request.Form("Submitted") = "login" Then
    ' Declare our variables
    Dim objConn, objRS, strSQL
 
    ' Create Connection Object
    Set objConn = Server.CreateObject("ADODB.Connection")
    objConn.Open strConnect
 
    ' Build SQL String
    strSQL = "SELECT * FROM MemberInfo WHERE Username='" & Request.Form("Username") & "'"
 
    ' Create Recordset Object
    Set objRS = Server.CreateObject("ADODB.Recordset")
    objRS.Open strSQL, objConn
 
    If objRS.EOF Then
        '================================================
        ' Does the Username exist?
        ' If not, set strFailed and destroy all objects.
        ' We'll then display the login form again.
        '================================================
        strFailed = "Invalid Username"
        objRS.Close
        Set objRS = Nothing
        objConn.Close
        Set objConn = Nothing
    Else
        '================================================
        ' Username exists - is the password correct?
        ' If not, set strFailed and destroy all objects.
        ' We'll then display the login form again.
        '================================================
        If objRS.Fields("Password") <> Request.Form("Password") Then
            strFailed = "Invalid Password"
            objRs.Close
            Set objRS = Nothing
            objConn.Close
            Set objConn = Nothing
        Else
            '================================================
            ' Username and password are valid.
            ' Set session variable.
            ' Destroy all objects.
            ' Redirect to secret page
            '================================================
    &