In order to fulfill my commitment to you, we will now write the "Database and ASP Program", which can be applied to both IIS and PWS security pages carefully.
Sneak peek, or let's take a look at the ASP program (password.asp) first.
<%
Function Checkpassword (Name, Password)
Dim Conn, param, RS
Set conn = Server.CreateObject ("ADODB. Connection ")
param = "Driver={microsoft Access driver (*.mdb)};"
Conn. Open param & ";d bq=" & Server.MapPath ("Book2.mdb")
sql = "SELECT * from key Where name= '" & Name & "' and Password = '" & Password & ""
Set RS = conn. Execute (SQL)
If Rs. EOF Then
' If no data records exist
Checkpassword = False
Else
Checkpassword = True
End If
End Function
%>
' Write a function, Use this function to book2.mdb the database to the name and password (that is, username and password), and then use the Select command to select from the key datasheet a data record that matches the name and password passed in by the function; Then ... Else statement to determine whether there is a qualifying data record in the data table key and, accordingly, to return the corresponding result to the function.
<%
If IsEmpty ("passed") Then session ("passed") = False
' Judge whether the session ("passed") of the Internet users is empty, that is, whether there is no session information, if it is the first time the Internet users to start the following program.
Head = "Please enter your name and password"
Name = Request ("Name")
Password = Request ("Password")
If Name = "" Or Password = "" Then
Head = "Please enter your name and password"
' Because it's the first comer, so Name = Request (' name ') and Password = Request ("Password") are equal to an empty string, session ("passed") = False, statement: If not session (" Passed ") (see below) is set up, so the" username and password "page (see figure below) is displayed.
ElseIf not Checkpassword (Name, Password) Then
Response.Write "User name or password error"
Response.End
' If the user entered the username and password is incorrect, then display the description information: "User name or password error
Else
Session ("passed") = True
End If
' Of course, the session ("passed") will equal true when the "User name and password" entered by the surfer are correct.
If not session ("passed") Then
' If not session (' passed ') then does not appear, you will not be able to display the "User name and password" page, but go directly to the encrypted Web page.
%>
' We can use the session object to store session information for a particular user, even if the client jumps from one Web page to another Web page, and the session information still exists. So here we use the Session object to store the information of the Surfer, as long as you pass the password verification, the session ("passed") on the note that you have passed the password verification, so in the session object's validity period, If you visit the Web page again, you do not have to enter the user name and password can be directly to the encrypted page.
'-= This eliminates the HTML code for entering the user name and Password page =-
The page that enters the user name and password is as follows:
<%
Response.End
End If
%>