CodeIgniter 4 login system with user role management and 2FA

A login system built on if ($role == 'admin') falls apart fast. The CI4 Starter Kit uses granular roles & permissions: every page gets Create/Read/Update/Delete flags per role, menus adapt automatically, and it's all managed from the UI.

One-time payment · unlimited projects · In Indonesia? Lynk.id QRIS/VA

The real thing

Click a screenshot to enlarge it. The full demo video is on the main page.

From a "role" column to real roles & permissions

Most CodeIgniter 4 login examples store a single role column on the users table and check it with if-else in controllers and views. The moment you need something new, say a Finance role that can view records but not delete them, you're combing through dozens of files.

This kit replaces that with RBAC: a user has one or more roles, each role has permissions per page, and routes are guarded by filters. Adding a role happens in the admin UI, without touching code.

A secure login

  • Log in with username or email
  • Forgot & reset password by email (single-use token)
  • Per-IP rate limiting + automatic account lockout
  • Forced password change on first login
  • CSRF, security headers, HttpOnly cookies, bcrypt

User roles with RBAC

  • Create/Read/Update/Delete permissions per page
  • One user can hold multiple roles
  • Sidebar & dashboard tiles adapt to the role
  • Route filters + UI buttons follow permissions

2FA & company login

  • Optional TOTP 2FA (Google Authenticator) + recovery codes
  • LDAP / Active Directory login (optional)
  • Demo seeder: 6 accounts with different roles

User management + audit

  • Add users, activate/deactivate, reset password & 2FA, unlock
  • Login As User (impersonate) + Superadmin protection
  • Audit log: who, what, when, IP, before → after values

How to set up a new user role

Example: a Finance role that can only view and create invoices.

  1. Create the role and tick its permissions

    Under Roles & Permissions, create Finance and tick Read and Create for the invoices page. Leave Update and Delete off.

  2. Add the permission filter to routes

    Routes the role isn't allowed to use are rejected, even if someone types the URL directly.

    $routes->get('invoices', 'Admin\Invoices::index', $p('invoices'));
    $routes->post('invoices/(:num)/delete', 'Admin\Invoices::delete/$1', $p('invoices', 'delete'));
  3. Check permissions in a controller when needed

    For example, to hide a button or a column.

    $canEdit = $this->can('update');           // current page
    $canSeeUsers = $this->can('read', 'users'); // another page
  4. Assign the role to users

    In User Management, pick one or more roles. Sidebar menus, dashboard tiles, and action buttons update immediately.

A typical role column vs the CI4 Starter Kit

Feature"role" columnCI4 Starter Kit
Different menus per roleif-else in viewsAutomatic from permissions
Adding a new roleEdit many filesFrom the admin UI
Per-action permissions: view, create, edit, delete✕ No✓ Yes
One user with several roles✕ No✓ Yes
Password reset by emailSometimes✓ Yes
2FA, rate limit & lockout✕ No✓ Yes
Audit log✕ No✓ Yes

Buy now on Gumroad

Common questions

How is this different from CodeIgniter Shield?

Shield is CodeIgniter's official authentication library: it gives you login plus groups and permissions in code, but no admin screens. The CI4 Starter Kit is a complete application with its own auth (no Shield dependency) and the UI to manage users, roles, permissions, menus, and the audit log.

How many roles can I create?

As many as you need. The demo seeder includes 6 accounts with different roles as examples, and new roles can be added any time from the admin UI.

Is 2FA mandatory?

No. 2FA is optional, works with authenticator apps like Google Authenticator, and comes with recovery codes in case a phone is lost.

Can users sign in with company accounts (LDAP / Active Directory)?

Yes, optionally. The LDAP/AD server is configured from the Settings menu without code changes, and the bind password is stored encrypted. If you don't use it, login works with regular local accounts.