Password Confirmation Flow for Logged In Users in Laravel 6.2

Brijpal Sharma
php laravel   Publish on:-October 10th, 2019 , Category:- Web Development


In this tutorial, we learn how to use password confirmation in Laravel 6.2. Laravel update the password confirmation process in new version 6.2.

Laravel released v6.2 9-Oct-2019 with a new password confirmation feature that allows the user to re-enter the password when the user performs sensitive actions like Github so, in this post, we see step by step how its work.

Step: 1 Create a new Laravel 6.2 application

To create a new project just enter flow command in cmd.

laravel new pass_confirmation

After installing the application, we need to generate default auth in Laravel but we know in Laravel the previous version make: auth command was removed so we use the new command.

composer require laravel/ui --dev

php artisan ui vue --auth

After that Laravel generates default auth for the user now make a register for a user.

Step: 2 create a new controller 

Create a new controller to by using this command

php artisan make:controller Settings/PasswordController

And update Password Controller by this code

namespace App\Http\Controllers\Settings;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class PasswordController extends Controller
{
    public function create()
    {
        return view('secret');
    }
}

Step: 3 Create a new view 

We are creating a new view that is shown after the user re-enters the password.

resources/views/secret.blade.php.

Update with this code

@extends('layouts.app')
@section('content')
  <div >
    <div >
      <div >
        <h1>Add a New SSH Key</h1>
        <p>This page is only shown after password confirmation.</p>
      </div>
    </div>
  </div>
@endsection

 

Now create a new file resources/views/auth/passwords/confirm.blade.php.

confirm.blade.php

@extends('layouts.app')

@section('content')
<div >
  <div >
    <div >
      <div >
        <div >{{ __('Confirm Password') }}</div>

        <div >
          {{ __('Please confirm your password before continuing.') }}
          {{ __('We won\'t ask for your password again for a few hours.') }}

          <form method="POST" action="{{ route('password.confirm') }}">
            @csrf

            <div >
              <label for="password" >{{ __('Password') }}</label>

              <div >
                <input id="password" type=password name=password required autocomplete="current-password">

                @error('password')
                  <span role="alert">
                    <strong>{{ $message }}</strong>
                  </span>
                @enderror
              </div>
            </div>

            <div >
              <div >
                <button type=submit >
                  {{ __('Confirm Password') }}
                </button>

                @if (Route::has('password.request'))
                  <a href="{{ route('password.request') }}">
                    {{ __('Forgot Your Password?') }}
                  </a>
                @endif
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
@endsection

 

Step: 4 Create a route which I want to use re-enter password from the user

Route::get('/settings/ssh/create', '[email protected]')->middleware('password.confirm');

Now for the test when you go to this localhost:8000/settings/ssh/create you will see this page.

Password Confirmation Flow for Logged In Users in Laravel 6.2

So here we completed tutorial on Password Confirmation Flow for Logged In Users in Laravel 6.2.


Brijpal Sharma

Hello, My Name is Brijpal Sharma. I am a Web Developer, Professional Blogger and Digital Marketer from India. I am the founder of Codermen. I started this blog to help web developers & bloggers by providing easy and best tutorials, articles and offers for web developers and bloggers...


0 Comments

You must be logged in to post a comment.