User Authenication - ADMIN area

I use the login script from this site for many separate areas of my websites. It's a great script, but I've always wanted some form of admin area to easily add, modify, and delete users. This tutorial uses six files that create a small admin area which allows someone to add, change password, and delete users. If you are using the original login script and haven't changed the table name or field names, then the only thing you need to change is your DSN on the last file, variables.cfm.

The original login area shouldn't be hard to find, it is always the highest viewed tutorial. It is located at http://tutorial8.easycfm.com/

<!--- This is the index.cfm file --->

<cfinclude template="variables.cfm">
<!--- Include the variables file so one change updates all templates --->

<!--- Get all records from the database that match this users credentials --->
<cfquery name="qList" datasource="#dsn#">
    SELECT *
    FROM #tablename#
</cfquery>

<html>
  <head>
    <title>Admin</title>
  </head>

<body>
<!--- Simple HTML form at the top to insert a user into the database --->

<form method="POST" action="adduser.cfm">
   <p align="center">
      <font size=
"2" face="Century Gothic">add user:</font><br>
      <input type="text" name="user_name" size="20">
   </p>
   <p align=
"center">
      <input type="submit" value="Submit" name="B1">
      <input type=
"reset" value="Reset" name="B2">
   </p>
</form>
<center>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="35%">
   <tr>
      <td width=
"25%" bgcolor="#000000" align="center">
         
<font color="#FFFFFF" face="Century Gothic" size="2">User</font>
      </td>
      <td width=
"25%" bgcolor="#000000" align="center">
         
<font color="#FFFFFF" face="Century Gothic" size="2">Details</font>
      </td>
      <td width=
"25%" bgcolor="#000000" align="center">
         
<font color="#FFFFFF" face="Century Gothic" size="2">Delete User</font>
      </td>
  </tr>
  
<cfoutput query="qList">
  <tr>
      <td width=
"25%">
         
<font face="Century Gothic" size="2">&nbsp;#user_name#</font>
      </td>
      <td width=
"25%" align="center">
         <a href=
"user_info.cfm?user_name=#user_name#"><font face="Century Gothic" size="2">info</font></a>
      </td>
      <td width=
"25%" align="center">
         <a href=
"deluser.cfm?user_name=#user_name#"><font face="Century Gothic" size="2">del</font></a>
      </td>
   
<!--- List all the current users and provide two options for each, info and del --->
   </tr>
</cfoutput>
</table>

</center>
</body>

</html>

<!--- NEW FILE: adduser.cfm --->
<!--- This file receives a user_name from the HTML form in the index.cfm then ADDS it to the db and goes back to the index --->
<!--- Since there is nothing on this file, all you'll see is the index.cfm page blink and then the new username appears --->

<cfinclude template="variables.cfm">

<cfquery name="addusers" datasource="#dsn#">

INSERT INTO #tablename# (user_name )
VALUES ('#user_name#')

</cfquery>

<CFLOCATION URL="index.cfm">

<!--- NEW FILE: deluser.cfm --->
<!--- This file receives a user_name from the HTML form in the index.cfm then DELETES it from the db and goes back to the index --->
<!--- Since there is nothing on this file as well, all you'll see is the index.cfm page blink and then the new username disappear --->

<cfinclude template="variables.cfm">
<cfquery name="delusers" datasource="#dsn#">
    DELETE FROM #tablename# WHERE user_name = '#url.user_name#'
</cfquery>

<CFLOCATION URL="index.cfm">

<!--- NEW FILE: user_info.cfm --->
<!--- This file receives a user_name from the link on the index.cfm then QUERIES info from the db --->

<cfinclude template="variables.cfm">
<cfquery name=
"user_info" datasource="#dsn#">
   select *
   from #tablename#
   where user_name = '#url.user_name#'
</cfquery>

<html>

<head>
    <title>Admin</title>
</head>

<body>

<form method="POST" action="user_info_update.cfm?user_name=<cfoutput>#user_info.user_name#</cfoutput>">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="40%">

<!--- The form fields are populated from the query and then sent to the next file which actually updates the database with the changes--->

<tr>
    <td width="47%" align="right">user:</td>
    <td width="4%">&nbsp;</td>
    <td width="49%">
        <input type="text" name="user_name" size="20" value="<cfoutput>#trim(user_info.user_name)#</cfoutput>">
    </td>
</tr>

<tr>
    <td width=
"47%" align="right">pass:</td>
    <td width=
"4%">&nbsp;</td>
    <td width=
"49%">
       
<input type="text" name="user_pass" size="20" value="<cfoutput>#trim(user_info.user_pass)#</cfoutput>">
    </td>
</tr>
</table>

<br>

<p align="center">
    <input type="submit" value="Submit" name="B1">
    <input type=
"reset" value="Reset" name="B2">
</p>
</form>
</body>
</html>

<!--- NEW FILE: user_info_update.cfm --->
<!--- This file receives the update info from user_info.cfm then UPDATES the db and goes back to the index --->

<CFSET user_name = form.user_name>
<CFSET user_pass = form.user_pass>
<cfinclude template="variables.cfm">

<cfquery name="user_info" datasource="#dsn#">
   UPDATE #tablename#
   SET
          user_pass='#user_pass#'
   where user_name = '#url.user_name#'
</cfquery>

<CFLOCATION URL="index.cfm">

<!--- NEW FILE: variables.cfm --->
<!--- If you are using the original login script without any changes all you have to change is your DSN in this file. --->

<CFSET dsn = "[your-datasource]">
<CFSET tablename =
"tblAdmins">



All ColdFusion Tutorials By Author: Rhino
  • Auto Event Emailer
    Queries the database everyday and sends an email automatically when certain events happen.
    Author: Rhino
    Views: 15,737
    Posted Date: Friday, December 13, 2002
  • Column View Output
    Ever wanted your data to be output in a column view such as mailing labels are? Use this code and change only a few lines and your data will be output in a table with 3 columns and as many rows as you have data. A great alternative to the standard row based view. Very easy to modify.
    Author: Rhino
    Views: 8,061
    Posted Date: Wednesday, February 25, 2004
  • Count Down
    Easy CFM file that counts down from a distant date to the present. Can show how many days, months, or years.
    Author: Rhino
    Views: 12,830
    Posted Date: Friday, December 13, 2002
  • Enter-Update same form
    I hate creating duplicate forms where one is for entry and an identical one is for udpating. This code lets you use one form for both purposes.
    Author: Rhino
    Views: 10,028
    Posted Date: Wednesday, April 7, 2004
  • Form processor with individual link email
    This tutorial shows how to process a form and generate a random string that is put on the end of a link. When the user clicks the link it goes to their personal page.
    Author: Rhino
    Views: 10,197
    Posted Date: Wednesday, March 31, 2004
  • Form with 2 Submit Buttons
    An easy way to have a form with 2 or more submit buttons where each one does a different thing. One can count a rows in a DB, then next can actually submit the query. Possibilities are limitless.
    Author: Rhino
    Views: 14,284
    Posted Date: Monday, October 9, 2006
  • IP checker
    Checks to see where the user came from and then decides where to send them.
    Author: Rhino
    Views: 13,740
    Posted Date: Friday, December 13, 2002
  • Use checkboxes on update pages
    Do you have an update page and want to use checkboxes on the page? This tutorial will go over the two steps needed.
    Author: Rhino
    Views: 9,793
    Posted Date: Wednesday, March 31, 2004
  • User Authenication - ADMIN area
    This script provides a simple admin area for the login script written by Pablon on this site. You can list, add, change pass, and delete users.
    Author: Rhino
    Views: 12,242
    Posted Date: Monday, March 29, 2004
  • Website Monitor
    Do you have a website that you'd like to monitor but would rather not pay outrageous fees to some company? This simple script will monitor uptime for you website. It is the barebones version and can be easily modified into something highly useful.
    Author: Rhino
    Views: 12,522
    Posted Date: Wednesday, March 24, 2004