User Guide

Table Of Contents
384 Chapter 16: Securing Applications
In the Application.cfc onRequestStart method, or a ColdFusion page or CFC method called by
the method, you have the following:
<cflogin>
<cfif NOT IsDefined("cflogin")>
<cfinclude template="loginform.cfm">
</cfif>
<cfabort>
<cfelse>
<!--- Code to authenticate the user based on the cflogin.user and
cflogin.password values goes here. --->
<!--- If User is authenticated, determine any roles and use a line like the
following to log in the user. --->
<cfloginuser name="#cflogin.name#" Password = "#cflogin.password#"
roles="#loginQuery.Roles#">
</cflogin>
A simple login form looks like the following:
<cfform name="loginform" action="#CGI.script_name#?#CGI.query_string#"
method="Post">
<table>
<tr>
<td>username:</td>
<td><cfinput type="text" name="j_username" required="yes"
message="A username is required"></td>
</tr>
<tr>
<td>password:</td>
<td><cfinput type="password" name="j_password" required="yes"
message="A password is required"></td>
</tr>
</table>
<br>
<input type="submit" value="Log In">
</cfform>
Using a browser dialog box to get user information
Application authentication does not require you to use a login form; you can rely on the browser
to display its standard login dialog box, instead. To do so, your
cflogin tag body returns an
HTTP status 401 to the browser if the user is not logged in or if the login fails; that is, if it does
not have a valid cflogin structure. The browser displays its login dialog box. When the user clicks
the login button on the dialog box, the browser returns the login information as an HTTP
Authorization header to ColdFusion, which puts the information in the
cflogin tag’s cflogin
structure.
This technique has the advantage of simplicity; you do not need a login form and the user gets a
familiar-looking login page. You must be careful of security issues, however. The browser sends
the user name and password in a base64-encoded string, not just when the user logs in, but with
each request. Use SSL (Secure Sockets Layer) for all page transactions to protect the user ID and
password from unauthorized access.