CodeIgniter 4 Authentication Login and Registration

User authentication is a standard security mechanism, It allows identified users to access any digital application or website. In this tutorial, we will learn you how to build a simple auth system with login and signup functionalities using MySQL.
So let’s implement Codeigniter 4 Authentication Login and Registration. look files structure:
  • authentication-login-registration
    • app
      • Config
        • App.php
        • Constants.php
        • Database.php
        • Routes.php
      • Models
        • UserModel.php
        • SettingsModel.php
        • LogsModel.php
        • EmailconfigModel.php
      • Controllers
        • Auth
          • AccountController.php
          • LoginController.php
          • PasswordController.php
          • RegistrationController.php
          • SettingsController.php
          • UsersController.php
      • Views
        • auth
          • edit-user.php
          • profile.php
          • register.php
          • settings.php
          • starter.php
          • user-logs.php
          • users.php
          • auth
            • forgot.php
            • login.php
            • reset.php
          • components
            • navbar.php
            • notifications.php
          • edits
            • edit-user.php
          • emails
            • activation.php
            • confirmation.php
            • footer.php
            • header.php
            • notification.php
            • reset.php
          • layouts
            • auth.php
            • default.php
            • default-table.php
          • modals
            • add-user.php
    • public
      • .htaccess
      • index.php
      • favicon.ico
    • .htaccess
    • .env
    • css
    • vendor
      • bootstrap
      • datatables
      • fontawesome
      • jquery
  • .env
Here some are pretty simple steps you have to follow to create a simple Authentication Login and Registration.
Step 1 – Install Codeigniter 4 Application
To handle the actual install you would use the following command in your terminal.
Step 2 – Display Errors
You may turn on the feature to errors, go to the app/Config/Boot/production.php and change display_errors prop value to 1 from 0.
OR Second method is go to Codeigniter site and download the application
Step 3: Create the Database and Table
Step 4 – Basic App Configurations
Now, you need to some basic configuration on the app/config/app.php file.
Step 5: Setup and Configure Database access
Update the file app/Config/Database.php OR .env file:
i) .env
ii) Database.php
Step 6: Update routes file
Add/Update code the file app/Config/Routes.php in your CodeIgniter installation with you controller’s name.
Step 7: Create and Update Model for user Auth module
Create model files are named UserModel.php, SettingsModel.php, LogsModel.php and EmailconfigModel.php inside “app/Models” folder.
i- UserModel.php
ii- SettingsModel.php
iii- LogsModel.php
vi- EmailconfigModel.php
Step 8: Create/Update controllers for user Auth
Create controllers files are named UsersController.php, RegistrationController.php, LoginController.php, PasswordController.php, AccountController.php and SettingsController.php inside “app/Auth/Controllers” folder.
i- UsersController.php
ii- RegistrationController.php
iii- LoginController.php
vi- PasswordController.php
v- AccountController.php
vi- SettingsController.php
Step 9: Create views
Create views files are named login.php, forgot.php and reset.php inside “app/Views/auth/auth” folder.
i- login.php
ii- forgot.php
iii- reset.php
Create views files are named navbar.php and notifications.php inside “app/Views/auth/components” folder.
i- navbar.php
ii- notifications.php
Create views files are named edit-user.php inside “app/Views/auth/edits” folder.
i- edit-user.php
Create views files are named header.php, footer.php, activation.php and confirmation.php inside “app/Views/auth/emails” folder.
This file contains the header section of the emailtemplates.
i- header.php
This file contains the footer section of the emailtemplates
ii- footer.php
iii- activation.php
iv- confirmation.php
Create views files are named auth.php, default.php and default-table.php inside “app/Views/auth/layouts” folder.
i- auth.php
This file contains the header/footer section of the webpage. The Bootstrap library is used to provide a better UI
ii- default.php
This file contains the header/footer section of the webpage. The Bootstrap library is used to provide a better UI
iii- default-table.php
This file contains the header/footer section of the webpage. The Bootstrap library is used to provide a better UI
Create views files are named add-user.php inside “app/Views/auth/modals” folder.
i- add-user.php
Create views files are named edit-user.php, profile.php, register.php, settings.php, starter.php, user-logs.php and users.php inside “app/Views/auth” folder.
i- edit-user.php
ii- profile.php
iii- register.php
vi- settings.php
v- starter.php
vi- user-logs.php
vii- users.php
Step 10: Run Application
Conclusion
We learned how to create authentication and user management system features in the Codeigniter 4 Application.
However, this was just the beginning of the Codeigniter authentication and user management system example. You can extend and more components if required in the Codeigniter 4 Application