Laravel - Authentication

Laravel - Authentication

 

Laravel - Authentication


Validation is the way toward identifying the client's qualifications. In web applications, validation is overseen by sessions that take the info parameters, for example, email or username and password, for client identification. On the off chance that these parameters coordinate, the client is said to be validated.

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.

<?php

namespace App\Http\Controllers;

use App\Http\Requests;
use Illuminate\Http\Request;

class HomeController extends Controller{
   /**
      * Create a new controller instance.
      *
      * @return void
   */
   
   public function __construct() {
      $this->middleware('auth');
   }
   
   /**
      * Show the application dashboard.
      *
      * @return \Illuminate\Http\Response
   */
   
   public function index() {
      return view('home');
   }
}

As a result, the scaffold application generated creates the login page and the registration page for performing authentication. They are as shown below −

Login

Login Page

Registration

Register

Manually Authenticating Users

Laravel utilizes the Auth façade which aids in physically confirming the clients. It incorporates the endeavor method to check their email and password.

Consider the accompanying lines of code for LoginController which incorporates every one of the capacities for confirmation −

<?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');
      }
   }
}
Reactions

Post a Comment

0 Comments

close