CodeIgniter 4 was released last February 2020 and it intentionally does not provide an internal authentication or authorization class. So you can either code it yourselves or use any available authentication library for CodeIgniter 4.
What is the best authentication library for CodeIgniter 4? You may want to try these two libraries for your next CodeIgniter 4 projects.
Ion Auth
Ion Auth is one of popular authentication library for CodeIgniter since CodeIgniter 2. The project is actively developed and supported by the community. It is safe for you to use it on a production site.
Notable Ion Auth features:
- User email activation
- Login attempts check
- Use Bcrypt/Argon2 hash
- Role based access control (RBAC)
You may download the library from the Ion Auth code repository here.
How to Get Started with Ion Auth
Ion Auth can be installed easily by using composer command.
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
Then, create Ion Auth configuration file in your config directory.
<?php namespace Config;
class IonAuth extends \IonAuth\Config\IonAuth
{
// set your specific config
// public $siteTitle = 'Example.com'; // Site Title, example.com
// public $adminEmail = 'admin@example.com'; // Admin Email
// public $emailTemplates = 'App\\Views\\auth\\email\\';
// ...
}
Enable the migration in config and run migration to create the authentication related tables.
php spark migrate:latest -n IonAuth
If you wish to seed some data, you may run the seeder from the terminal using the CLI command.
php spark db:seed IonAuth\Database\Seeds\IonAuthSeeder