Ion Auth 4 for CodeIgniter 4
repository·4·Indexed 25 days ago
https://github.com/benedmunds/codeigniter-ion-authA simple, lightweight authentication library designed specifically for CodeIgniter 4 applications. It provides user authentication, group management, and password hashing using bcrypt or argon2. The library includes support for database migrations, seeds, and a transparent migration path from SHA1 hashing to modern methods.
What's inside Ion Auth 4
- For improved security when using Ion Auth 4, it is highly recommended to configure your CodeIgniter application to use encrypted database sessions.
Migrate from SHA1 hashing to modern methods
4The
sha1hash method is no longer supported due to security concerns. However, Ion Auth provides a transparent migration path for existing users:- Automatic Migration: After upgrading to Ion Auth 3/4, any user logging into your application will have their password automatically migrated to the new hashing method (e.g.,
bcryptorargon2) upon a successful login. - Identification: You can identify old SHA1-based passwords in your database by looking for entries in the password field that do not start with a
$sign. - Cleanup: Once most users have migrated, you may choose to invalidate any remaining users who still possess SHA1-based hashes.
- Automatic Migration: After upgrading to Ion Auth 3/4, any user logging into your application will have their password automatically migrated to the new hashing method (e.g.,
Install Ion Auth 4.x for development (Git method)
4If you want to develop against the library directly, clone the repository and checkout the
4branch. You must then manually register the namespace in your CodeIgniter 4Config/Autoload.phpfile using thepsr4array.$ git clone https://github.com/benedmunds/CodeIgniter-Ion-Auth.git $ cd CodeIgniter-Ion-Auth $ git checkout 4In
Config/Autoload.php:public $psr4 = [ ... 'IonAuth' => ROOTPATH . 'CodeIgniter-Ion-Auth', ... ];Implement Ion Auth Controllers and Routes
4To use Ion Auth in your application, you should extend the base
Authcontroller and define routes inConfig/Routes.php.1. Create a Custom Controller Extend
\IonAuth\Controllers\Auth. If you wish to use custom views, copy theion-auth/Views/authfolder to your application'sViewsfolder and uncomment the$viewsFolderproperty.2. Configure Routes Group your authentication routes under an
authprefix and point the namespace toIonAuth\Controllers.// App/Controllers/Auth.php <?php namespace App Controllers; class Auth extends \IonAuth\Controllers\Auth { /** * If you want to customize the views, * - copy the ion-auth/Views/auth folder to your Views folder, * - remove comment */ // protected $viewsFolder = 'auth'; }// Config/Routes.php $routes->group('auth', ['namespace' => 'IonAuth\Controllers'], function ($routes) { $routes->add('login', 'Auth::login'); $routes->get('logout', 'Auth::logout'); $routes->add('forgot_password', 'Auth::forgot_password'); // ... other routes });Install Ion Auth 4.x via Composer
4Ion Auth 4 requires CodeIgniter 4.x, PHP 7.1, and Composer. To install it in an existing or new Composer project, you must first set the minimum stability to
devand add the repository via Git before requiring the package.For an existing project:
- Set minimum stability to
dev. - Add the IonAuth VCS repository.
- Require the package using the
4.x-devversion.
For a new project:
- Initialize composer.
- Set minimum stability to
dev. - Add the IonAuth VCS repository.
- Require the package using the
4.x-devversion.
# For an existing project $ composer config minimum-stability dev $ composer config repositories.ionAuth vcs git@github.com:benedmunds/CodeIgniter-Ion-Auth.git $ composer require benedmunds/codeigniter-ion-auth:4.x-dev # For a new project $ composer init $ composer config minimum-stability dev $ composer config repositories.ionAuth vcs git@github.com:benedmunds/CodeIgniter-Ion-Auth.git $ composer require benedmunds/codeigniter-ion-auth:4.x-dev- Set minimum stability to
Upgrade from Ion Auth 2 to Ion Auth 4
4Upgrading from Ion Auth 2 is a multi-step process involving file replacement, configuration updates, and database migrations:
- Perform the standard file overwrite as described in the Ion Auth 3 upgrade steps.
- Review
config/ion_auth.phpfor modified options. - Run the appropriate SQL migration file for your database environment:
- MySQL:
sql/migrating_from_ionauth2/migrate.sql - PostgreSQL:
sql/migrating_from_ionauth2/migrate.postgre.sql - SQL Server:
sql/migrating_from_ionauth2/migrate.mssql.sql
- MySQL:
- Database Cleanup: If you were not using the SHA1 hash method, you may drop the
saltcolumn from theuserstable. - SHA1 Users: If you were using the SHA1 hash method, follow the Migrating from SHA1 guidance.
- Code Audit: Check your application code for modified or removed
Ion_auth_modelfunctions.
Load the Ion Auth library
4You can load Ion Auth in your CodeIgniter 4 controllers or models just like any other library:
$ionAuth = new \IonAuth\Libraries\IonAuth();Alternatively, you can configure CodeIgniter to autoload the library.
Upgrade from Ion Auth 3 to Ion Auth 4
4To upgrade from a previous revision of Ion Auth 3 to the current version:
- Download the latest Ion Auth 3 revision.
- Overwrite
libraries/ion_auth.phpandmodels/ion_auth_model.phpwith the new versions. - Overwrite all files in the
language/directory with the new versions. - Review
config/ion_auth.phpfor any configuration changes or evolutions required by the new version.
Upgrade Ion Auth 4
4To upgrade to a newer version of Ion Auth 4:
- Download the latest version.
- Overwrite
Libraries/IonAuth.phpandModels/IonAuthModel.phpwith the new versions. - Overwrite all files in the
Languages/directory. - Review
Config/IonAuth.phpfor any new configuration options or changes.
Note: If you are upgrading from Ion Auth 2, refer to the
UPGRADING.mdfile included in the package.Install and use Ion Auth 4
4Ion Auth 4 provides simple and lightweight authentication specifically for CodeIgniter 4 applications.
Note: This version is not backwards compatible with previous versions of Ion Auth, although the database schema remains compatible for migration purposes.
To get started, refer to the following files in the repository:
- Installation instructions:
INSTALLING.md - Detailed usage guide:
USERGUIDE.md - Upgrade instructions:
UPGRADING.md
For quick implementation reference, the repository includes example controllers and views that demonstrate how to integrate the library without requiring custom base controllers (like
MY_Controller).- Installation instructions:
Set up Ion Auth Database (Migrations and Seeds)
4Ion Auth requires database tables. Use the provided migrations and seeds to set up the relational database.
1. Run Migrations Execute the migration command using the
IonAuthnamespace. Ensure thatConfig\Migrationsis set toenabled => truein your application.2. Run Seeds You can use the
IonAuthSeederto insert default data. Note the difference in path separators between Windows and Linux.Migration Command:
php spark migrate -n IonAuthInstall Ion Auth 4
4To install Ion Auth 4 in your CodeIgniter 4 application, follow these steps:
- Download: Get the latest version from the GitHub zipball.
- Copy Files: Copy the package files to your application. You can either:
- Copy specific files to their corresponding folders (e.g.,
IonAuth/Config/IonAuth.phptoapp/Config/IonAuth.php). - Copy the entire directory structure into
app/ThirdParty/IonAuth/.
- Copy specific files to their corresponding folders (e.g.,
- Run Migrations: Execute the migration file located in
Database/Migrations/using the following command:$ php spark migrate:latest -n IonAuth - Seed Default Data: Insert default data. Ensure
Config\Migrations:enabledis set totruein your configuration.
Windows:
$ php spark db:seed IonAuth\Database\Seeds\IonAuthSeederLinux:
$ php spark db:seed IonAuth\\Database\\Seeds\\IonAuthSeederDefault Credentials:
- Email:
admin@admin.com - Password:
password