Ion Auth Lightweight Auth System

Ion Auth is a simple and lightweight authentication library for the CodeIgniter framework.

Features

  • Registration
  • Login and Logout
  • Forgotten Password
  • Change Password Method
  • Focused on security
  • User groups
  • “Remember Me” funtionality
  • Extremely Customizable

Installation

Download it from github.

Copy the files from this package to the correspoding folder in your application folder. For example, copy Ion_auth/config/ion_auth.php to system/application/config/ion_auth.php.

Prepare your database

In order for the Ion to work, you’ll have to create some tables in your database. All you need to do is run a couple of queries. You will find them in the sql folder. Just open the ion_auth.sql, copy paste the queries and run them in your phpMyadmin.

After this procedure, the following new tables are created: ‘groups’, ‘users’, ‘users_groups’ and ‘login_attempts’.

By default, one administrator user is created with the following credentials.

  • Email: admin@admin.com
  • Password: password

Make sure you change these before going online.

Autoload the library

Open application/config/autoload.php and ‘ion_auth’ to the autoload libraries list.

Configuration options

To change the configuration options simply edit the config/ion_auth.php file. What you’ll usually want to change are:

$config['site_title'] = "Mywebsite.com";   // Site Title, example.com
$config['identity'] = 'username';     // A database column which is used to login with

$config['use_ci_email'] = true; // Send Email using the builtin CI email class, if false it will return the code and the identity
$config['email_config'] = array(
    'mailtype' => 'html',
    'protocol' => 'smtp',
    'smtp_host' => 'mail.mywebsite.com',
    'smtp_user' => 'myemail@mywebsite.com',
    'smtp_pass' => '1234567'
);

Class Function Reference

logged_in()

Check to see if a user is logged in. Returns boolean TRUE if the user is logged in FALSE if the user is not logged in. Example:

if (!$this->ion_auth->logged_in())
{
    redirect('auth/login');
}

user()

Get a user. If a user id is not passed the id of the currently logged in user will be used. Example:

$user = $this->ion_auth->user()->row();
echo $user->email;

Troubleshooting

Call to undefined function inet_pton

To solve this, open ion_auth_model.php go to line 1983 and replace with this one:

return $ip_address;

Learning Resources

Post A Comment

Anti-Spam Quiz: