PHP Classes
elePHPant
Icontem

Authentication: A session and cookie based authentication class

Recommend this page to a friend!
  Info   View files View files (11)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2003-07-31 (13 years ago) RSS 2.0 feedStarStarStarStar 65%Total: 7,106 All time: 260 This week: 1,042Down
Version Licenses Categories
authentication 1.0GNU General Publi...User Management
Description Author

A simple class, used for implementation of an usual member and administration pages.

It uses sessions and cookies if desired. It requires the PEAR DB library and Smarty template system.

Picture of Kevin Cadman
Name: Kevin Cadman <contact>
Classes: 2 packages by
Country: South Africa South Africa

Details
Project: Authentication
Version: 1
Author: Kevin Cadman (Kevin@ZAgamers.za.net)
Date: 2003-07-31

About this file
----------------
This is the documentation for the Authentication class. 

If you have any questions or suggestions regarding this class, please
email me at Kevin@ZAgamers.za.net

TODO:
-----­-

Level Support. Not just "admin or normal user" but specific level support.
Module Support. Have specific privileges per module, or filename.

Authentication
---------------
The class Authentication is used to simply create "members sections" on pages.

The quick and easy setup:

MAKE SURE YOU HAVE THE FOLLOWING:

The PEAR DB library. (http://pear.php.net)
The Smarty Template System. (http://smarty.php.net)
	
Files:
home.php -> A test "members page." Also demonstrates "logging out."
DB_INFO.php -> Your database details.
authadmin.php -> The file included on "admin" member pages. A demonstration as to how this is done.
auth.php -> The file included on "member pages." (See home.php)
login.php -> The file used to gain Authentication. Demonstrates cookie support too.
common.php -> The file used to include all the Classes. Also used to setup DB on NON Member pages.
Authentication.php -> The main Authentication class.
templates/login.tpl -> The smarty template for the login page.


Here follows a description of the public interface:

function Authentication() - Constructor Funtion
Must be passed the $db object, which is a global variable defined by DB_INFO.php.

function StartAuth()
Used to Start the Authentication. It is passed the user's inputted username, password and if they're using
cookies. Checks to see if a record exists in the $userTable with the given data.
If so, calls the setAuthed() function. 

function setAuthed()
This will register the relevant sessions and cookies (if need be.) 

function CheckAuth()
Used to check the validity of the user's session credentials. 
This is used by the auth.php & authadmin.php files. (Please see those files for usage instructions.)
If cookies are used, it will check to see if valid cookies exist. If they do, it'll assign the sessions
with the cookie's data. 

function GetDetail()
Used to get the current user's fields. This is quite handy, as you can add as many fields as you want
to the table. (Example: Telephone, Fax, Address)
Then, to retrieve this information, simply call GetDetail with the field name. 
As such:
$auth = new Authentication($db);
echo "Your name is".$auth->GetDetail("name");

function AuthKill
This is used to kill the sessions & cookies. Used for logout purposed.

TABLE STRUCTURES:

You need mySQL. The queries are pretty simple, so I'm sure it'd be pretty straight forward to
port this to another database, as it is using the PEAR DB class. Change your database type in
DB_INFO.php and modify queries accordingly. (I however have no idea why anybody would want to do this.)

CREATE TABLE site_users (
  id tinyint(3) NOT NULL auto_increment,
  username varchar(255) default '0',
  password varchar(255) default '0',
  sess_id varchar(255) default '0',
  firstname varchar(255) default '0',
  lastname varchar(255) default '0',
  admin enum('Y','N') default NULL,
  email varchar(100) default NULL,
  PRIMARY KEY  (id)
) TYPE=MyISAM;

INSERT INTO site_users 
VALUES("1", "admin", "admin", "0", "Admin", "Admin", "Y", "admin@admin.com");

Defaultly, you may login as admin/admin. (This coincidentally is an admin account!)

Play around with it a bit, I'm sure you'll find it extremely useful for those "Quick and Dirty" sites.
The class doesn't require an exceptional knowledge of PHP, and can be set up in under 5 minutes.

If you have anything to contribute, email me. Kevin@ZAgamers.za.net
  Files folder image Files  
File Role Description
Accessible without login Plain text file auth.php Example Included on desired "members" pages
Accessible without login Plain text file authadmin.php Example Included on "admin" pages
Plain text file Authentication.php Class Authentication class file
Accessible without login Plain text file common.php Aux. Includes outside classes
Accessible without login Plain text file COPYING Lic. Licensing Information
Accessible without login Plain text file DB_INFO.php Conf. Database connection setup
Accessible without login Plain text file home.php Example Example "home" page
Accessible without login Plain text file LICENSE Lic. License Information
Accessible without login Plain text file login.php Example An example login page
Accessible without login Plain text file login.tpl Data Login template. MAKE SURE IN "templates" directory! VERY IMPORTANT!
Accessible without login Plain text file README Doc. Read Me Information

 Version Control Unique User Downloads Download Rankings  
 0%
Total:7,106
This week:0
All time:260
This week:1,042Down
 User Ratings  
 
 All time
Utility:84%StarStarStarStarStar
Consistency:87%StarStarStarStarStar
Documentation:78%StarStarStarStar
Examples:68%StarStarStarStar
Tests:-
Videos:-
Overall:65%StarStarStarStar
Rank:652