Using the FileSystemObject
Heya all. Can anyone see what I have done wrong.
I have created a txt file with a password. Also inserted all the code in the login.asp file.
Every time I test the for I get default 'The page cannot be displayed'
The code is right out of the book. Just cant understand where I have gone wrong.
Code here:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
Dim sErrorMessage
Dim sReferrer
If Request.Form("txtReferrer") = "" Then
sReferrer = Request.QueryString("accessdenied")
Else
sReferrer = Request.Form("txtReferrer")
End If
If sReferrer = "" Then
sReferrer = "search.asp"
End If
If Request.Form("txtUserName") <> "" And _
Request.Form("txtPassword") <> "" Then
Const ForReading = 1
Dim oFileSystemObject
Dim oTextStream
Dim sFileLocation
Dim sTempString
Dim arrTemp
Dim bUserFound
If Request.Form("btnLogin") <> "" Then
sFileLocation = Server.MapPath("Tools/users.txt")
' Create an instance of the FileSystemObject
Set oFileSystemObject = Server.CreateObject("Scripting.FileSystemObject")
' Create a reference to our text file so we can read from it
Set oTextStream = oFileSystemObject.OpenTextFile(sFileLocation, ForReading)
' Read in each line until we reach the end of the file
Do While (Not oTextStream.AtEndOfStream = True)
' Read a line
sTempString = oTextStream.ReadLine()
' If the line contains text
If Len(sTempString) > 0 Then
' The line should hold the username and password, separated by a tab
' Split the line based on a tab, so we get the username and password
' in two separate array elements
arrTemp = Split(sTempString, vbTab)
If IsArray(arrTemp) Then
' An UBound of 1 means two elements in the array, the username
' and the password. If we haven't found both, we do not continue
If UBound(arrTemp) = 1 Then
' Compare array elements with username and password
If arrTemp(0) = Request.Form("txtUserName") And _
arrTemp(1) = Request.Form("txtPassword") Then
bUserFound = True
Exit Do
End If
End If
End If
End If
Loop
' Close our textstream and clean up our objects
oTextStream.Close
Set oTextStream = Nothing
Set oFileSystemObject = Nothing
If bUserFound = True Then
Session("MM_Username") = Request.Form("txtUserName")
Response.Redirect(sReferrer)
Else
sErrorMessage = "<span class=""clsErrorMessage""><br>" & _
"Login failed. Please type a valid username and password</span>"
End If
End If
End If
%>
TA
Mal.
|