万卷书   首页 > 电脑书籍 > Asp > 利用ASP给主页加密之二
 

利用ASP给主页加密

我们的目的是:

   *验证用户是否经过授权并根据结果设置相应的验证状态

   *如果用户是经过授权的,验证状态置1

   *如果用户是没有授权的,验证状态置0

下面显示的是verify.htm页的代码,你可以根据实际情况作一些相应的修改。

< %

' Create a command object. This object serves to run our queries

Set Cm = Server.CreateObject(“ADODB.Command”)

' Specify the system DSN path

Cm.ActiveConnection =“LoginDSN”

' Now it's time for the query. We need to check the user information

' against the table tUsers

Cm.CommandText=“SELECT * FROM tUsers WHERE ”& _

“UserName='”& Request.Form(“UserName”) &“' AND ”& _

“UserPassword='” & Request.Form(“UserPassword”) & “'”

' Set the query type. 1 means it is a SQL statement

Cm.CommandType = 1

' Retrieve the results in a recordset object

Set Rs = Cm.Execute

' We now check if the user is valid. If user is valid, the recordset MUST

' haverecord. Otherwise it is empty. If user exists, we set authentication

' status to 1 and send the user to appropriate page, say welcome.htm.

' Else send the user back to login.htm

If Rs.EOF Then

Session(“Authenticated”) = 0

Response.Redirect (“login.htm”)

Else

Session(“Authenticated”) = 1

Response.Redirect (“welcome.htm”)

End If

% >

下一页