CFLOGIN MADE EASY
<!--
       I am making this tutorial very brief so you do not have to hear me
       very long. Quick and to the point. This CFLOGIN tutorial will help
       you keep you pages of login and logout and session management all
       set to 1 page included in the Application.cfm file. The following
       code is all to be placed in your Application.cfm file. Read each
       comment I have included and it will explain (without a lot of detail)
       exactly what is taking place. Although this code is fully functional
       as it is written now, I do recomend you include a few scripts such as
       invalid_login and other obvious scripts which should be included in a login.
                                                                             -Wesley Geddes-
-->

<!-- 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>



All ColdFusion Tutorials By Author: Wesley Geddes
  • CFLOGIN MADE EASY
    This will show how you can validate a user then use CFLOGIN and determine the users admin level within the Application.cfm file. Not hard whatsoever. This one is correct Pablo.
    Author: Wesley Geddes
    Views: 22,147
    Posted Date: Sunday, February 6, 2005
  • Replacing Ugly Text With Nice Text Graphics
    This tutorial will show you how to replace a text string with letter graphics. This is very nice and includes a zip file with all source ready to run. This also includes an active interactive example right here on the tutorial.
    Author: Wesley Geddes
    Views: 18,711
    Posted Date: Friday, July 15, 2005
  • Using Arrays for Your Sites Security
    You must have a basic understanding of Arrays! This tutorial will showe you how to implement many security checks with 1 database field using Arrays.
    Author: Wesley Geddes
    Views: 15,853
    Posted Date: Wednesday, June 22, 2005