asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search










Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Code Samples
Components
Tools
New
Free
Downloads
Vendors
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

There is a simple alternative to NT authenication is to cheat. Here's a "no NT involved" version of security.inc; just put

<!--#INCLUDE FILE="security.inc"--> 

at the top of each ASP page you want to protect, and put this in security.inc:


<%
'does the session know the user?
UserID=Session("UserID")
Rejected=False

If IsEmpty(UserID) Or IsNull(UserID) Or UserID="" Then
Attempted=False

'Figure out who we are, for later
URL=Request.ServerVariables("QUERY_STRING")
If IsEmpty(URL) Or URL="" Then
URL="" ' just in case
Else
URL="?" & URL
End If
URL=Request.ServerVariables("SCRIPT_NAME") & URL

'check for POSTed authentication information
UserID=Request.Form("UserID")
UserPWD=Request.Form("UserPWD")

If IsEmpty(UserID) Or IsNull(UserID) Or UserID="" Then
Rejected=True
Else
' insert your own checking here -- this is deliberately lame
If UserID="Foo" AND UserPWD="Foo" Then
'wahoo!
'set the session variable
Session("UserID")=UserID
Rejected=False
Else
Attempted=True
Rejected=True
End If
End If
End If

If Rejected Then
If Attempted Then
Title="Authentication Failure"
Else
Title="Please Authenticate"
End If
%>
<!--#INCLUDE FILE="authentication_form.htm"-->
<%
Response.End 'stop processing before it gets back to your page
End If
' ... otherwise, on with your normal page.
%>
The authentication page (authentication_form.htm) could look like this:

	<html><head><title><%=Title%></title></head>
<h1><%=Title%></h1>
<form action="<%=URL%>" method="POST">
Username: <input type="text" name="UserID" size="20"><br>
Password: <input type="password" name="UserPWD" size="20"><br>
<input type="submit">
</form>
</html>
You could just as easily paste this HTML in where the INCLUDE is, but it makes it a little harder to edit using FrontPage. Note that anyone trying to hit authentication_form.htm is going to find it a little... well, useless. I'll leave it as an exercise to the reader how to get around this.

How does security.inc work?

If the user has authenticated already, security.inc notices that the UserID session variable is set and passes control back to your page. If they haven't, it sends them a form which asks for their username and password. When they submit that information, security.inc checks it and either gives them the form again or passes control back to your page.

The extra code is there to tweak the form if the user failed authentication (as opposed to simply not having authenticated yet), and to preserve any query information in the URL.

Note that if the user doesn't accept the ASP cookie (or is using a non-cookie-aware browser), the session variable won't be preserved and they'll be continuously asked to re-authenticate. You should modify the authentication page so that it warns users of this.




email this code sample to a colleague

Related Articles
Jan 24, 1997 - Simple ASP Chat
This 15 Seconds' issue contains source code and step by step instructions for creating a chat session using Active Server pages, HTML and a standard web browser. Also demonstrated is writing and reading of a file with an Active Server page.
[Read This Article]  [Top]
Apr 6, 1997 - Creating a List Server with ASP
This issue describes how to make a list server using Active Server, SQL Server, and Stephen Genusa's ASPMail Component. Included are source and instructions for adding the user to the list from a Active Server page, removing the user from the list via a Active Server page, and sending mail to the whole list.
[Read This Article]  [Top]
Apr 22, 1997 - Active Server Components with VS 5.0
A rewrite of part one of a four-part series on Active Server objects. A simple example of creating a Active Server Component in Visual Studio 5.0 using the Active Template Library 2.0. The example component retrieves the user's cookie, if not available issues a new 128-bit cookie. Included in the issue is the source code and step by step instructions. This issue has been rewritten to illustrate the use of Visual Studio 5.0 and ATL 2.0 in writing Active Server Components.
[Read This Article]  [Top]
Jul 31, 1997 - Creating a Category Site with ASP
In this issue 15 Seconds implements a catalog site that is build with Active Server pages and SQL Server. Along with the implementation there is source code and a discussion of the advantages and disadvantages of creating a catalog site that gets its content from a database. Included are pages for displaying products, creating a menu page, category page, and running a search across a database.
[Read This Article]  [Top]
Sep 11, 1997 - The Last-Modified Header in ASP
A complete discussion of the Last Modified header and the Expires header including the effect they have on Active Server page and various browsers.
[Read This Article]  [Top]
Related Books
Working with Active Server Pages
Understanding ActiveX and OLE: A Guide for Developers and Managers
Professional Active Server Pages
Professional Visual C++ 5.0 ActiveX/COM Control Programming
Teach yourself Active Web Database Programming in 21 Days
Unlocking Active Server Pages
Active Server Pages for Dummies
Active Server Pages How-To : The Definitive Active Server Pages Problem-Solver
Active Server Pages Unleashed
Programming Active Server Pages
Teach Yourself Active Server Pages in 14 Days
The Active Server : A Developer's Guide Creating Dynamic Web Content
Active Server Pages Black Book
Professional Active Server Pages 2.0
Professional Asp and Rds Database Programming
Special Edition Using Active Server Pages
Microsoft® BackOffice® Resource Kit, Second Edition
Related Knowledge Base Articles
HOWTO: Disabling Cookies Sent by Active Server ...
Q163010 - 1997.06.23
IIS Execution File Text Can Be Viewed in Client
Q164059 - 1997.06.23
INF: How to Access SQL Server Within Active Ser...
Q169377 - 1997.06.23
How To Use Response.Redirect in a Server Script
Q159402 - 1997.06.23
How To Stop Users from Displaying a Frame Outsi...
Q159977 - 1997.06.23

Support the Active Server Industry



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers