dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Web
Expertise: Beginner
Dec 3, 1999

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Password-Protect ASP Pages Using Session Variables

The Active Server Pages Session object provides a quick way to password-protect your pages and force users to log in. The trick is to set a Session variable once the user has been authenticated and then check for the value of the variable at the beginning of each ASP page. For example, this script, session.asp, checks the password ("mypassword") that is passed from the form. If the password is correct, Session("loginokay") is set to true.

 
<%@ Language=VBScript %>
<%
if Request("password1")="mypassword" then
Session("loginokay") = True
end if
%>
<HTML>
<HEAD>
</HEAD>
<BODY>
<%if Not Session("loginokay") then %>
<form action="session.asp" name=login method=post>
<INPUT type="password" id=password1 name=password1>
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
</form>
<%else%>
<a href="showall.asp">Continue</a>
<%end if%>
</BODY>
</HTML>

In subsequent pages, such as showall.asp shown here, check the value of Session("loginokay") and either allow the person in or send the person to the login page.

 
<%@ Language=VBScript %>
<%
If Not Session("loginokay") Then
    Response.Redirect "session.asp"
End If
%>
<HTML>
<HEAD>
</HEAD>
<BODY>
You are logged in.
</BODY>
</HTML>
Ken Cox
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date