PDA

View Full Version : ASP VBScript Login app error 800a003e


VenomSnake
09-15-2004, 10:37 PM
When I run my ASP login script I get this error message after trying to log in:

Microsoft VBScript runtime error '800a003e'
Input past end of file
/calendar/login.asp, line 17

Here is the app


<!--#include file="config.asp" -->
<%
go = Request.QueryString("go")
Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
Set MyTextFile=MyFileObject.OpenTextFile("C:\Inetpub\db\auth.txt")
if Request.Form("username") <> "" then
WHILE NOT MyTextFile.AtEndOfStream
If MyTextFile.ReadLine = "a " & Request.form("username") & " " & Request.form("password") THEN
MyTextFile.Close
Session("DiaryAdmin") = true
If Request.Form("go") <> "" then
Response.Redirect(Request.Form("go"))
Else
Response.Redirect("/member.asp")
End If
Else
If MyTextFile.ReadLine = "u " & Request.form("username") & " " & Request.form("password") THEN
MyTextFile.Close
Session("DiaryUser") = true
If Request.Form("go") <> "" then
Response.Redirect(Request.Form("go"))
Else
Response.Redirect("/member.asp")
End If
Else
msg = "Invalid Username or Password"
End If
End If
go = Request.Form("go")
WEND
MyTextFile.Close
End If
%>


Here is Line 17
If MyTextFile.ReadLine = "u " & Request.form("username") & " " & Request.form("password") THEN

The App works fine with certain user names, but with others it gives the error message. The error also doesn't seem to have any relavence to weather it is a user or admin (a or u at the begining). I have a return at the end of my text file, and the ones that don't work are even between ones that do work, which seems odd to me. Does anyone know what could be wrong? Also, does anything think this method (using a text file for login) isn't a good idea, as I was thinking of trying a database or something if that would work better. Thanks.

glenngv
09-16-2004, 04:38 AM
Execute ReadLine only once inside the loop by storing its output in a variable.
The conditional operator for VBscript is AND and not & (this is used for string concatenation).
The 2nd and 3rd conditions in the compound If...Then statement are not actually conditions as they don't use conditional operators such as =, <, > or <>.

See the code below. I assume you want to compare username and password to empty strings.

dim line
...

while not MyTextFile.AtEndOfStream
line = MyTextFile.ReadLine
If line = "a " and Request.form("username")="" and Request.form("password")="" THEN
MyTextFile.Close
Session("DiaryAdmin") = true
If Request.Form("go") <> "" then
Response.Redirect(Request.Form("go"))
Else
Response.Redirect("/member.asp")
End If
Else
If line = "u " and Request.form("username")="" and Request.form("password")="" THEN
MyTextFile.Close
Session("DiaryUser") = true
If Request.Form("go") <> "" then
Response.Redirect(Request.Form("go"))
Else
Response.Redirect("/member.asp")
End If
Else
msg = "Invalid Username or Password"
End If
End If
go = Request.Form("go")
wend

You can also store the retrieved username and password in a variable so that you don't always request them every time you need them. Retrieving field data from the Form collection takes longer than retrieving from a variable.