Authentication system using cflogin, cfloginuser and cflogout
cfloginuser.cfm
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>How to create authentication system (cflogin, cfloginuser, cflogout) in coldfusion</title>
</head>
<body>
<h2 style="color:OrangeRed; font-style:italic">cfloginuser tag example: how to create simple login logout system</h2>
<hr width="625" align="left" color="Crimson" />
<br />
<cfif IsDefined("LoginButton")>
<cfif Form.UserName eq "jenny" and Form.Password eq "password">
<cflogin>
<cfloginuser name="jenny" password="password" roles="admin">
</cflogin>
</cfif>
</cfif>
<cfif IsDefined("LogoutButton")>
<cflogout>
</cfif>
<cfif IsUserLoggedIn() eq "Yes">
<cfform action="" method="post" name="LogoutForm">
<cfinput
type="submit"
name="LogoutButton"
value="Logout"
style="height:45px; width:150px; font-size:large; font-style:italic; font-weight:bold; color:DeepPink;"
>
</cfform>
<h3 style="color:SeaGreen;">
Only logged in user can see this image.
</h3>
<img src="Images/CuteBird.jpg" />
</cfif>
<cfif IsUserLoggedIn() eq "No">
<cfform name="LoginForm" method="post" format="html">
<table border="1" cellpadding="5" cellspacing="0" bordercolor="SeaGreen">
<tr>
<td colspan="2" bgcolor="DarkSeaGreen" style="color:Snow; font-size:large" align="center">
User Login Form
</td>
</tr>
<tr valign="top">
<td style="color:OliveDrab; font-weight:bold">
UserName
</td>
<td style="color:Crimson;">
<cfinput
name="UserName"
type="text"
style="background-color:OliveDrab; color:Snow; width:250px; height:25px; font-size:large; font-style:italic; font:'Comic Sans MS', cursive"
>
*jenny
</td>
</tr>
<tr valign="top">
<td style="color:OliveDrab; font-weight:bold">
Password
</td>
<td style="color:Crimson;">
<cfinput
name="Password"
type="password"
style="background-color:OliveDrab; color:Snow; width:250px; height:25px; font-size:large; font-style:italic; font:'Comic Sans MS', cursive"
>
*password
</td>
</tr>
<tr valign="top">
<td colspan="2" align="right">
<cfinput
type="submit"
name="LoginButton"
value="Login"
style="height:45px; width:150px; font-size:large; font-style:italic; font-weight:bold; color:OliveDrab;"
>
</td>
</tr>
</table>
</cfform>
</cfif>
<br />
</body>
</html>