<%
Dim conn, rsCheckuser, sqlQuery
Dim strPassword1, strPassword2, strType, strUsername
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Project.mdb") & ";"
strUsername = Request.Form("formUsername")
strPassword1 = Request.Form("formPassword")
sqlQuery = "SELECT password, type FROM [user] WHERE username ='" & strUsername & "'"
set rsCheckuser = conn.execute(sqlQuery)
If NOT rsCheckuser.EOF Then
strPassword2 = rsCheckuser.Fields("password")
strType=LCase(rsCheckuser.Fields("type"))
END IF
rsCheckuser.Close
conn.Close
Set rsCheckuser=Nothing
Set conn=nothing
If strPassword1 = strPassword2 Then
Session("passCorrect") = True
If strType = "admin" then
Response.Redirect "successfulLogin.asp?name=" & strUsername
Else
Response.Redirect "staffframe.asp"
End If
Else
Session("passCorrect") = False
Response.Redirect"failedLogin.html"
End if
%>
Something like that maybe is what you are trying to ... this way does the same thing and is maybe a tiny bit simpler:
<%
Dim conn, rsCheckuser, sqlQuery
Dim strPassword, strType, strUsername
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Project.mdb") & ";"
strUsername = Request.Form("formUsername")
strPassword = Request.Form("formPassword")
sqlQuery = "SELECT type FROM [user] WHERE username ='" & strUsername & "'" AND password='" & strPassword & "'"
set rsCheckuser = conn.execute(sqlQuery)
If rsCheckuser.EOF Then
strType = LCase(rsCheckuser.Fields("type"))
END IF
rsCheckuser.Close
conn.Close
Set rsCheckuser=Nothing
Set conn=nothing
SELECT CASE strType
CASE "admin"
Session ("passCorrect") = True
Response.Redirect "successfulLogin.asp?name=" & strUsername
CASE ""
Session ("passCorrect") = False
Response.Redirect "failedLogin.html"
CASE ELSE
Session ("passCorrect") = True
Response.Redirect "staffframe.asp"
END SELECT
%>
That only works if there are no NULL or blank values in they [type] field.
Edited by dj1811 - 22 February 2005 at 7:39pm