PHP Classes

Authentication: A session and cookie based authentication class

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 62%Total: 7,158 All time: 271 This week: 660Down
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
Age: 41
All time rank: 3594 in South Africa South Africa
Week rank: 170 Up4 in South Africa South Africa Equal

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 (11)  
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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:7,158
This week:0
All time:271
This week:660Down
 User Ratings  
 
 All time
Utility:80%StarStarStarStarStar
Consistency:83%StarStarStarStarStar
Documentation:75%StarStarStarStar
Examples:66%StarStarStarStar
Tests:-
Videos:-
Overall:62%StarStarStarStar
Rank:879