authenticate.asp
<%
Dim URL
URL = Request.QueryString
' 獲得URL.
%>
<html>
<body>
<FORM METHOD=POST ACTION="/validate.asp">
<INPUT TYPE=HIDDEN NAME="URL" VALUE="<%=URL%>">
' 將URL保存到一個隱藏變量中.
用戶名:
<INPUT TYPE=TEXT NAME="txtName">
口令:
<INPUT TYPE=PASSWORD NAME="txtPassword">
<INPUT TYPE=SUBMIT>
</FORM>
</body></html>
再用validate.asp文件獲取傳遞給它的信息,從數據庫中讀取用戶名和口令,以判斷是否給用戶授權。
validate.asp
<%
Dim strUserName, strPassword
strUserName = Request.form("txtName")
strPassword = Request.form("txtPassword")
' 從表單中讀取用戶名和口令.
' 建立數據庫連接...
Dim strSQL
strSQL = "select * from ValidUsers WHERE UserName = " & _
strUserName & " AND Password = " & _
strPassword
' 進行SQL查詢.
Dim rs
Set rs = Conn.Execute(strSQL)
If rs.EOF Then
' 如果recordset不為空, 則用戶名有效.
Session("bolAuthenticated") = True
' 將bolAuthenticated 設為True.
Response.Redirect Request.form("URL")
' 將用戶傳遞到來過的URL.
Else
Response.Redirect "/notvalidated.asp
[1]