Session Replacement in ASP - The Login Page (Page 4 of 5 )
The login page contains a form which gets submitted to itself, after which the results are handed to the database. The database comes back with a valid sessionID or with the value –1 if the login fails:
<% Dim oCnn, oRs, sMessage, sSessionID If Len(Request.Form(“cmdSubmit”)) > 0 Then
sSessionID = oRs.Fields(0).Value ORs.Close OCnn.Close Set oCnn = Nothing
If sSessionID = -1 Then SMessage = “username or password invalid” Else Response.Redirect (“/?id=” & sSessionID) End If Else SMessage = “ ” End If %>
Again, we establish a connection to the database, and this time pass the form elements “usid” en “password” to the stored procedure usp_CheckLogin.
We store the returning value in a variable called sSessionID and close the connection to the database. If the value of sSessionID is –1, we give a message which will be displayed in the form we just filled out, otherwise we redirect to the home page and tag the querystring(“id”) with the new sessionID.