Password Confirmation Flow for Logged In Users in Laravel 6.2

  • Brijpal Sharma

    October 10th, 2019 , Posted On:- Web Development

    php laravel


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 class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <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 class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">{{ __('Confirm Password') }}</div>

                <div class="card-body">
                    {{ __('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 class="form-group row">
                            <label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>

                            <div class="col-md-6">
                                <input id="password" type="password" class="form-control @error('password') is-invalid @enderror" name="password" required autocomplete="current-password">

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

                        <div class="form-group row mb-0">
                            <div class="col-md-8 offset-md-4">
                                <button type="submit" class="btn btn-primary">
                                    {{ __('Confirm Password') }}
                                </button>

                                @if (Route::has('password.request'))
                                    <a class="btn btn-link" 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', 'PasswordController@create')->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.


About Author
  • user profile
    Brijpal Sharma

    brijpalsharma99@gmail.com, January 29th, 2018

    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 Comment

You must be logged in to post a comment.