Hi there this is my first post I was looking for some help with a script for a project in college.
I need to make a login page that accesses an MS access database and checks the user input against the user name and password in the database.
I have been having a problem with the comparison it seems to reach the end of the database without finding the username even though it is typed correctly :(
thank you for any help
This is the form for the login and below it is the code for logon2.asp. The username field is named UserName and password Password in the database
<form name = "frmlogin" action = "logon2.asp" method = "post">
<p><font color="white">Login Page</font></p>
<p><font color="white">Login name</font></p>
<input type = "text" name = "login" value = "">
</br></br>
<p><font color="white">Password</font></p>
<input type = "text" name = "pass" value = "">
</br></br>
<input type = "submit" value = "Submit">
<input type = "reset" value = "Reset Form">
</form> Logon2.asp
<%@ language = "VBScript" %>
<%Response.buffer = true%>
<html>
<!-- This include File below contains constants For use With the access database -->
<head>
<title>Logon Results</title>
</head>
<body bgcolor = "lemonchiffon">
<%
const adSearchForward = 1
dim tempstr, temppass
dim tempname
dim ObjRecSet
dim found
found = false
'create the object
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("aspDatabase.mdb"))
Set ObjRecSet = Server.CreateObject("ADODB.RecordSet")
'generate a recordset
ObjRecSet.Open "Users", conn, 2, 2
'copy data from form to data items
tempname = Request.Form("login")
temppass = Request.Form("pass") if len(tempname) = 0 then
Response.write("No data to search for ")
else
'setup string for searching the database
tempstr = "UserName = " & "'" & tempname & "'"
Response.Write("Number of Fields " & objRecSet.Fields.Count & "<br>")
ObjRecSet.MoveFirst
'pass tempstr as a parameter to the FIND method
ObjRecSet.Find tempstr,adSearchForward
If ObjRecSet.EOF then
Response.Write("<h1>" & tempname & " does not exist in the system " & "</h1>")
response.write("<a href = 'logon.html'>" & "Click to return to Logon Page" & "</a>")
Else
'Record found
If (ObjRecSet.Fields("UserName") = tempname) and (ObjRecSet.Fields("Password")= temppass)then
ObjRecSet.Fields("Logon") = "true"
Response.Write("Welcome to the system " & tempname & "<br>")
'Update the recordset and close everything down
ObjRecSet.Update
response.write("<a href = 'logon.html'>" & "Click to return to Logon Page" & "</a>")
End if
End If
End If
ObjRecSet.Close
Set ObjRecSet = Nothing %> </body>
</html>