Discussion Locked

web page security

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have my web site with many pages and would like to requre a password for a user to enter each page. but once a user enters the password they should not need to enter again for that time - like amazon.com works, i can lof in and it remembers my passwrod for each page I go to.

I want use asp and access db to do this. Any help on this is appreciated.

thanks - Davis

4 replies

by peyison

You can do what you are looking for using the Session object in ASP. At the start of each ASP page, enter code like:

<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>

<%
If IsEmpty(Session("UserId")) Then
Session("LoginFrom") = Request.ServerVariables("URL")
Response.Redirect "./login.asp"
End If

%>

The rest of your page goes here....

---------------

Then in login.asp, after you validate the user, add code like:

Session("UserId") = sUserId
If IsEmpty(Session("LoginFrom")) or Session("LoginFrom") = "" Then
Response.Redirect "nocookies.html"
Else
Response.Redirect Session("LoginFrom")
End If

The first block of code checks to see if the user has logged in already. If the Session variable "UserId" is empty, then the user has not logged in. If not, the code saves the URL of the current page in a Session variable called LoginFrom. This way the code knows where to return to after logging in. Then it redirects to the login page.

More to follow...

by peyison

Once in the login.asp page, after you have validated the user, save the userid to the Session variable called UserId. Then next few lines is used to see if the user has cookies turned off. If so, none of this works since the Session object needsto write a cookie to retain its state. If cookies are turned off, then the Session variable LoginFrom set back on the first page will be empty.

If cookies are turned on, then the code redirects back to the page that called it.

In order for this to work, you shouldn't link to the login.asp page directly. Instead, link to one of the other pages and let that page redirect to login.asp if needed.

Let me know if you need help with the login.asp page. Basically it should have a form that posts to the login.asp page. The form should contain an input box for id and one for password, and a submit button. Add VB script at the top of the page to see if the submit button is empty or not - if it's not then the submit button has been pressed,if it is empty then this is the first time loading the page. Something like:

If Not IsEmpty(Request.Form("cbtLogin")) Then
sUserId = Request.Form("tbxUserId")
sPassword = Request.Form("tbxPassword")

..validation stuff
..redirect stuff
EndIf

'If cbtLogin is empty, load the page like normal.

Once you have the UserId, look up the Password from the database Where Userid = sUserId and compare that password with sPassword.

Let me know if you need more info.
Hope this helps.

by tdavis9283

wow -this site is good. This is what I am looking for. I think I can do user validation from Access but will let you know if I run into questions. Thanks very much for you help!!!!

This discussion is closed to new replies.