<!-- Underneath is the SQL which I used in MYSQL to create the table -->
CREATE TABLE table_name (
id integer auto_increment Primary Key,
user varchar(20),
pass varchar(20),
admin integer
)
<!-- Variables which need to be defined -->
<cfparam name="URL.logout" default="0">
<cfparam name="invalid_login" default="0">
<!-- Define the datasource (DSN) name -->
<cfset dsource = "login">
<!-- Code will not be executed unless #FORM.username# IS NOT "" -->
<cfif structKeyExists(form,"username")>
<!-- Check Username, Password, and Level of Administration -->
<cfquery name="check_user" datasource="#dsource#">
SELECT user, pass, admin
FROM table_name
WHERE user = '#FORM.username#' and pass = '#FORM.password#'
</cfquery>
<!-- If there is a valid User then Login user -->
<cfif check_user.recordcount is not 0>
<!-- Log them in with a timeout of 30 minutes (1800 sec) and set level of Admin-->
<cflogin idletimeout="1800">
<cfloginuser
name = "#FORM.username#"
password ="#FORM.password#"
roles = "#check_user.admin#">
</cflogin>
<cfelse>
<!-- If an invalid Login Attemp, Set invalid to 1 for invalid login script -->
<cfset invalid_login = 1>
</cfif>
</cfif>
<!-- If index.cfm?logout=1 is clicked then Log The User Out -->
<cfif URL.logout is 1>
<cflogout>
<cflocation url="index.cfm">
</cfif>
<!--- Simple index.cfm file that logs you in --->
<cfif GetAuthUser() is "">
<form name="form1" method="post" action="index.cfm">
User: <input name="username" type="text" id="username"><br>
Pass:
<input name="password" type="text" id="password"><br>
<input type="submit" name="Submit" value="Submit">
</form>
<cfelse>
<p>User: <cfoutput>#GetAuthUser()#</cfoutput></p>
<a href="index.cfm?logout=1">Logout</a>
</cfif>