Laravel Authentication

In comparison to other framework, Laravel makes authentication very simple and almost everything is configured for you out of the box. You have to configure it. The authentication configuration file is located at “config/auth.php”, which contain several well documented options for tweaking the behaviour of the authentication services.

At its core, Laravel authentication facilities are made up of “guards” and “providers”. Guards define how users are authenticated for each request, and Providers define how users are retrieved from your persistent storage.
In Laravel, by default, it’s includes a “user.php” Eloquent model in your “app” directory (“app/user.php”). This model may be used with the default Eloquent authentication driver. If your application is not using the eloquent model, you may use the database authentication driver which uses the Laravel query builder.

When building the database for the app\user model, make sure the password column is at least 60 characters in length and string column length should be 255 characters. And also, you should verify that user table contains a nullable, string “remember_token” (used for store a token and ‘remember me’ option for users when logging into your application) column of 100 characters.

How to Start Authentication

Laravel provide several pre-built authentication controller, such as:

  • ForgotPasswordController.php
  • LoginController.php
  • RegisterController.php
  • ResetPasswordController.php
  • VerificationController.php

1. Setup Authentication

First open your terminal and run the command:
“php artisan make:auth”. But keep in mind, this command should be run on fresh laravel application.

After run this command, this will install a layout view, auth view, as well as routes for all authentication end-points. These files are located in “resources\views” directory.

Now, we have all views files and routes files, your application look like:
Home Page

Login Page

Register Page

2. Creating Database:

After setup the authentication, then create the database into your local server: in this, I have use “Wamp” server for Laravel project, with database LDb name:

After creating database, then go to your project and open “.env” file and do some changes: such as DB_DATABASE, DB_USERNAME and DB_PASSWORD.

3. Run Migration

Migration are like version control for your database which allowing you to easily modify and share the application’s database schema. Migrations are typically paired with Laravel’s schema builder to easily build your application’s database schema.

In this project, I have generated only database and no schema is created. After run the migration, it will automatically create the table in your database.
Run command: “php artisan migration”.

After run migration command, three tables will be automatically generated in your database such as migration, password reset and users.

Users’ field

Password_reset

Migration field
After completion of all process, your project will work properly with authentication process.
Note: In your “resources\views” directory, all of these views use the Bootstrap, CSS framework, but you are free to customize them however you wish.

Results

Register Page

Login Page

If you enter wrong password

© 2023 aynsoft.com - Website Development, Software Development Company India