- Laravel - Action URL
- Laravel - Dump Server
- Laravel - Pagination Customizations
- Laravel - Artisan Commands
- Laravel - Guest User Gates
- Understanding Release Process
- Laravel - Hashing
- Laravel - Encryption
- Laravel - Artisan Console
- Laravel - Authorization
- Laravel - Authentication
- Laravel - CSRF Protection
- Laravel - Contracts
- Laravel - Facades
- Laravel - Event Handling
- Laravel - Error Handling
- Laravel - Ajax
- Laravel - Sending Email
- Laravel - File Uploading
- Laravel - Validation
- Laravel - Session
- Laravel - Localization
- Laravel - Forms
- Laravel - Errors & Logging
- Laravel - Working With Database
- Laravel - Redirections
- Laravel - Blade Templates
- Laravel - Views
- Laravel - Response
- Laravel - Cookie
- Laravel - Request
- Laravel - Controllers
- Laravel - Namespaces
- Laravel - Middleware
- Laravel - Routing
- Laravel - Configuration
- Laravel - Application Structure
- Laravel - Installation
- Laravel - Overview
- Laravel - Home
Laravel Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Laravel - Authentication
Authentication is the process of identifying the user credentials. In web apppcations, authentication is managed by sessions which take the input parameters such as email or username and password, for user identification. If these parameters match, the user is said to be authenticated.
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 −
Controller
The controller which is used for the authentication process is HomeController.
<?php namespace AppHttpControllers; use AppHttpRequests; use IlluminateHttpRequest; class HomeController extends Controller{ /** * Create a new controller instance. * * @return void */ pubpc function __construct() { $this->middleware( auth ); } /** * Show the apppcation dashboard. * * @return IlluminateHttpResponse */ pubpc function index() { return view( home ); } }
As a result, the scaffold apppcation generated creates the login page and the registration page for performing authentication. They are as shown below −
Login
Registration
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 pnes of code for LoginController which includes all the functions for authentication −
<?php // Authentication mechanism namespace AppHttpControllers; use IlluminateSupportFacadesAuth; class LoginController extends Controller{ /** * Handpng authentication request * * @return Response */ pubpc function authenticate() { if (Auth::attempt([ email => $email, password => $password])) { // Authentication passed... return redirect()->intended( dashboard ); } } }Advertisements