WEB DEVELOPER SITE
TUTORIALS HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Laravel - Authentication


Authentication is the process of identifying the user credentials. In web applications, authentication is managed by sessions which take the input parameters such as email or username and password, for user identification.

Command

Laravel uses the following command to create forms and the associated controllers to perform authentication −

php artisan make:auth

This command helps in creating authentication scaffolding successfully, as shown in the following screenshot −

Authentication

Controller

The controller which is used for the authentication process is HomeController.

Manually Authenticating Users

Laravel uses the Auth façade which helps in manually authenticating the users. It includes the attempt method to verify their email and password.

Consider the following lines of code for LoginController which includes all the functions for authentication −

<?php

// Authentication mechanism
namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;

class LoginController extends Controller{
   /**
      * Handling authentication request
      *
      * @return Response
   */
   
   public function authenticate() {
      if (Auth::attempt(['email' => $email, 'password' => $password])) {
      
         // Authentication passed...
         return redirect()->intended('dashboard');
      }
   }
}