Discussion Locked

Check Logon before displaying the next

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

I am developing a website which needs high level security. I have coded a number of ASP programs which includes an ASP for logon process and they are interliked.

How do I enforce the user to use the website only after successfully logging-in? The user should not be allowed to use the website say by just supplying the name of the ASP other than the default (logon asp).

5 replies

by peyison

Each ASP page will need to verify that the user is logged in. Probably the easiest way to do this is using the Session object.

From your login page, after a user logs in save the UserId to a Session variable:

Session("UserId") = sUserId

(The name of the Session variable can be anything you want)

Then on all other ASP pages, check to see if the Session variable you set contains a value:

'at the top of the page:
If IsEmpty(Session("UserId")) or Session("UserId") = "" Then
'User is not logged in. Need to redirect to the login page
End if

You can also save the URL of the current page in a session variable so that once the user logs in you can redirect back to the page he initially tried to access:

If IsEmpty(Session("UserId")) or Session("UserId") = "" Then
Session("LoginFrom") = Request.ServerVariables("URL")
'(better to hard code the URL of this page if you can, rather than call Request.ServerVariables)
'redirect to the login page
End if

Then inthe login page, after the user logs in redirect to Session("LoginFrom").

One last note - if you have three pages that need to be accessed in order, and the user first goes to the second page, you can put the URL of the first page in Session("LoginFrom") so that once the user logs in he will be redirected back to the first page, not the second.

Hope this helps.

by gbworld

For high security, there are a couple of levels of security you need to address:

1. Data Security: To ensure this type of security, you need to ensure that all access to the database is secure. For SQL Server, this means at minimum stored procedures. For added security you should only allow access to the stored procedures via MTS roles (ie, programmed components). Only the dbo role should access the raw tables.

2. Code security. While ASP is great for modeling, for secure apps you should migrate as much code from ASP to VB COM+/MTS components as quickly as possible. To set up code for migration, consult:
http://www.asptoday.com/articles/20000121.htm

3. Logon security: To have a bit of logon security in ASP, just set a session token when the user logs on. This session token can then be tracked, expired, etc. GUIDs are great for tokens as they are 128 bit numbers expressed in hex. If you are using SQL Server, you can create a procedure to return NEWID() to be stored for this token (any number will do here, but GUIDs add an abstraction to the process that the system can generate for you).

The easiest way to use the token (will not work on a web farm) is in session:

<%
'... create token here
Session("token") = 'token'
%>

To check, you can either do a simple check (first draft):

<%
If session("token") <> vbNullString
'...
End If
%>

or run into a VB component for more info:

<%
Dim objToken 'As MyObject.clsToken
Set objToken = Server.CreateObject("MyObject.clsToken")
If objToken.CheckToken(Session("Token")) then
'..logged in
Else
'... not logged in
End If

This should give you a start.

Gregory A. Beamer
Internet Architecture Consultant
MCP: +I, SE, SD, DBA

This discussion is closed to new replies.