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
|