Introduction to Authentication System
Thank you for purchasing our script.
This guide should answer all your questions about how to use this script, you can browse the document
using the navigation sidebar on the left.
Description
Authentication System is a user authentication and access control management system built in object oriented PHP 5 with a MySQL database. Is lightweight, secure, flexible, customizable and simple application that allows you to protect and controll access for your page within your website.
Some of the features include:
- Easy implementation
- Installation wizard
- Very compact
- Lightweight MySQL database
- Works in all major browsers
- Basic protection against XSS attacks
- Spam protection using reCAPTCHA
- User access logs
- Encrypt passwords and cookies
- 100% Object Oriented
- Email templates
Installation
- Unzip the package in an empty directory and upload everything.
- Open a browser and go to the url where you put the Authentication System files.
- If you are running on a your own computer http://localhost/example/install/
- If on a live server http://www.example.com/install/
- Just follow the instructions and fill in the fields required to properly install the Authentication System.
Upgrade for 1.x to 1.4
These may include bug fixes or enhancements, and you may or may not wish to upgrade. It's always a good idea to backup everything up before you upgrade, especially if you have made any changes to the files, as the upgrade will overwrite all files.
- Backup your existing application files and database before making any changes.
- Delete the old files and folders, except config folder.
- Upload the new contents in your root directory, except config folder.
- Clear any cookies and your browser cache to avoid errors.
- Open a browser and go to the url where you put the Authentication System files.
- If you are running on a your own computer http://localhost/example/install/upgrade.php
- If on a live server http://www.example.com/install/upgrade.php
- Just follow the instructions to update your Authentication System.
NOTE:
- Always make a backup of your files and database first.
- It is strongly recommended not to upgrade your live website, make a copy of your website to another server and try to upgrade it first.
- If you have made any modifications in some files, your changes will be lost. Compare the new and old files and replace the necessary parts of code manually.
Usage examples
Create a simple PHP file or open the file you wish to protect and include at the top our file.
<?php //Include the common file require_once('common.php'); ?>
Protect your page (also at the top).
<?php //Check if the user is logged in if (!$authentication->logged_in()) header("Location: login.php"); ?>
Check the user group or if the current user is an admin.
<?php //Include the common file require_once('common.php'); //Check if the user is logged in if (!$authentication->logged_in()) header("Location: login.php"); ?> <?php if (!$authentication->is_group('member') AND !$authentication->is_admin()): ?> <p>You must be a admin or member to view this content.</p> <?php else: ?> <p>All signed in administrator or member can view this content.</p> <?php endif; ?>
Session data
//Eg: 2 $session->get('user_id') //Eg: 2 $session->get('group_id') //Eg: email@example.com $session->get('user_email') //Eg: John $session->get('first_name') //Eg: Doe $session->get('last_name') //Eg: 1 or 0 $session->get('user_status') //Return Unix timestamp $session->get('last_login') //The last ip logged $session->get('last_ip')
Get user e-mail
<?php if ($session->get('user_email')) { echo 'Your e-mail is:' . $session->get('user_email'); } ?>
Get user full name
<?php if ($session->get('first_name') AND $session->get('last_name')) { echo 'Your full name is:' . $session->get('first_name') . ' ' . $session->get('last_name'); } ?>
Get last login with Unix timestamp, see PHP date function.
<?php if ($session->get('last_login')) { echo 'Last login:' . date('d/m/Y H.i.s', $session->get('last_login')); } ?>
Functions
- create_user()
- update_user()
- delete_user()
- get_user()
- get_active_users()
- get_inactive_users()
- get_newest_users()
- activate_user()
- login()
- logged_in()
- logout()
- new_password()
- is_admin()
- check_email()
- add_group()
- update_group()
- delete_group()
- get_group()
- get_groups()
Create a new user
Function | Parameters | ||
---|---|---|---|
create_user() |
E-mail - string required Password - string required Additional data - multidimensional array required Status - integer optional Group id - integer optional |
Usage
$additional_data = array( 'first_name' => 'John', 'last_name' => 'Doe' ); $authentication->create_user('email@example.com', '1234', $additional_data, 1, 2);
Update a user
Function | Parameters | ||
---|---|---|---|
update_user() |
User id - integer required E-mail - string required Password - string required Additional data - multidimensional array required Status - integer optional Group id - integer optional |
Usage
$additional_data = array( 'first_name' => 'John', 'last_name' => 'Doe' ); $authentication->update_user(2, 'email@example.com', '1234', $additional_data, 1, 2);
Delete a user
Function | Parameters | ||
---|---|---|---|
delete_user() | User id - integer required |
Usage
$authentication->delete_user(2);
Get a user
Function | Parameters | Return | |
---|---|---|---|
get_user() | User id - integer required | array |
Usage
$authentication->get_user(2);
Get active users
Function | Parameters | Return | |
---|---|---|---|
get_active_users() | array |
Usage
$authentication->get_active_users();
Get inactive users
Function | Parameters | Return | |
---|---|---|---|
get_inactive_users() | array |
Usage
$authentication->get_inactive_users();
Get newest users
Function | Parameters | Default | Return |
---|---|---|---|
get_newest_users() | Limit - integer optional | 10 | array |
Usage
$authentication->get_newest_users();
Activate user
Function | Parameters | ||
---|---|---|---|
activate_user() |
E-mail - string required Code - string required |
Usage
$authentication->activate_user('email@example.com', '1234ABCD');
Login
Function | Parameters | ||
---|---|---|---|
login() |
E-mail - string required Password - string required Remember - boolean optional |
Usage
$authentication->login('email@example.com', '1234', true);
Check if the user is logged in
Function | Parameters | ||
---|---|---|---|
logged_in() |
Usage
$authentication->logged_in();
Logout
Function | Parameters | ||
---|---|---|---|
logout() |
Usage
$authentication->logout();
New password request
Function | Parameters | ||
---|---|---|---|
new_password() | E-mail - string required |
Usage
$authentication->new_password('email@example.com');
Check if the user is an admin
Function | Parameters | ||
---|---|---|---|
is_admin() |
Usage
$authentication->is_admin();
Check user group
Function | Parameters | ||
---|---|---|---|
is_group() | Group name - string required |
Usage
$authentication->is_group('special_guest');
Check email address
Function | Parameters | ||
---|---|---|---|
check_email() | E-mail - string required |
Usage
$authentication->check_email('email@example.com');
Add a new group
Function | Parameters | ||
---|---|---|---|
add_group() |
Name - string required Description - string required |
Usage
$authentication->add_group('Special guest', 'Description');
Update a group
Function | Parameters | ||
---|---|---|---|
update_group() |
Group id - integer required Name - string required Description - string required |
Usage
$authentication->update_group(2, 'Special guest', 'Description');
Delete a group
Function | Parameters | ||
---|---|---|---|
delete_group() | Group id - integer required |
Usage
$authentication->delete_group(2);
Get a group
Function | Parameters | ||
---|---|---|---|
get_group() | Group id - integer required |
Usage
$authentication->get_group(2);
Get the groups
Function | Parameters | Return | |
---|---|---|---|
get_groups() | array |
Usage
$authentication->get_groups();
Authentication configuration
Database tables
Description | Value |
---|---|
The users table | $config['table_users'] |
The groups table | $config['table_groups'] |
The user profiles table | $config['table_profiles'] |
The access logs table | $config['table_access_logs'] |
Website details
Description | Value |
---|---|
The title of your website | $config['site_title'] |
The site url of your website | $config['site_url'] |
The absolute path of your server | $config['absolute_path'] |
Administrator email address | $config['admin_email'] |
Registration settings
Description | Value |
---|---|
Default ID of user group | $config['default_group'] |
Default ID of admin group | $config['admin_group'] |
Enables or disables email activation | $config['email_activation'] |
Set true to be approved by the admin | $config['approve_registration'] |
Time for user activation | $config['email_activation_expire'] |
How long to remember the user (seconds) | $config['user_expire'] |
Welcome message | $config['email_subject_1'] |
Send new password | $config['email_subject_2'] |
New user registered | $config['email_subject_3'] |
General settings
Description | Value |
---|---|
Secret word of the token | $config['secret_word'] |
Number of items display per page (Admin) | $config['per_page_admin'] |
Enables or disables access logs for the users | $config['access_logs'] |
reCAPTCHA
Description | Value |
---|---|
Enables or disables reCAPTCHA | $config['recaptcha'] |
reCAPTCHA Public Key | $config['recaptcha_public_key'] |
reCAPTCHA Private Key | $config['recaptcha_private_key'] |
Database configuration
Description | Value |
---|---|
The hostname of your database server | $config['hostname'] |
The username used to connect to the database | $config['username'] |
The password used to connect to the database | $config['password'] |
The name of the database you want to connect to | $config['dbname'] |
The database type. Currently supported: mysql | $config['driver'] |
The character set used in communicating with the database | $config['char_set'] |
Email templates
Email templates are used for the emails sent (using HTML) from your website. You can customize the templates using your text. All templates are inside the folder templates/mail/, below the welcome template as an example:
<html> <head> <title>%%SITE_TITLE%%</title> </head> <body> <p>Hello %%FIRST_NAME%% %%LAST_NAME%%!</p> <p>Welcome and thank you for registering at %%SITE_TITLE%%!</p> <p>Here are your account details:</p> <p> Name: %%FIRST_NAME%% %%LAST_NAME%%<br /> Email address: %%EMAIL%%<br /> Password: *hidden* </p> <p> Thanks,<br /> %%SITE_TITLE%% </p> <p>* Do not respond to this email *</p> <p> This is an automatic email sent from our support system.<br /> Do not respond to this email, you will not receive any response! </p> <p><a href="%%SITE_URL%%" target="_blank">%%SITE_TITLE%%</a></p> </body> </html>
You may notice text that looks like this %%EMAIL%%. This is called a token and is used by the system to fill in information to be put in the email. In this case %%EMAIL%% is the token to display the user email.
Requirements (recommended)
- Operating System
- Linux
- Web server
- Apache
- MySQL 5+
- PHP 5.2+ (PDO extension required)
- PHP Settings
- Session: On
- Register Globals: Off
Files included
- Authentication library
- Database tables
- jQuery library
- jQuery UI
- jQuery plugin: Validation
- jQuery plugin: qTip2
- Custom JS files
- Minified
- Uncompressed for developers
- Default and Core CSS file: style.css
- Example: example folder
- Free support: on e-mail, the fastest way of support
Changelog
v1.5 (11/10/2012)
* Fix: Session data to display first name and last name
v1.4 (02/10/2012)
* New: Gravatar support
* New: Admin approval for new user registration
* New: Access logs
* New: Spam protection using reCAPTCHA
* Updated: Libraries
* Updated: Database tables
* Removed: AJAX calls
* Removed: jQuery effects
* Removed: Useless column display_name from database
v1.3 (02/07/2011)
* Few more fixes and enhancements
v1.2 (08/03/2011)
* New: Automatic cleaning of the users that do not have confirmed registration
* Fix: Check e-mail user
v1.1 (02/03/2011)
* New: Prevent security attacks known as session hijacking and session fixation
* New: Basic protection against XSS attacks
v1.0 (22/02/2011)
* Initial release
Credits
- jQuery
- jQuery plugin: Validation
- jQuery plugin: qTip2
- 960 Grid System
- SyntaxHighlighter
- Led Icons
- Retina Display Icons
Support notes
Right now we receive many emails and requests for support than we can manage quickly. Many times we can
answer the same day but others take much longer.
Before you send a request for support make sure you have done the following things:
- Read the full documentation file.
- Check if your question is not already in the Item Discussion section.
To be able to help solve a problem quickly, please read our profile page. We will do our best to help.