How to require re-entering password confirmation for specific routes in Laravel?

Salim Djerbouh

I have a secret route in Laravel that should sit behind a password confirmation protection (Like GitHub sudo mode when you're about to delete a repo or add a collaborator)

Route::get('/secret', 'DiariesController@index')->middleware(['auth', 'verified']);

But already authenticated users can easily access the routes

What I want is an extra layer of protection against physical access to the user's device

Here's what I have tried so far

DiariesController

public function index()
{
    if (session()->has('sudo')) {
        return view('secret.diaries');
    }
    auth()->logout();
    return redirect('/login');
}

And in LoginController

/**
 * The user has been authenticated.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  mixed  $user
 * @return mixed
 */
protected function authenticated(Request $request, $user)
{
    session(['sudo' => true]);
}

But this basically does nothing, I have to manually expire the sudo session key somehow

is there an easier way to achieve this?

Salman Zafar

The Laravel v6.2.0 release ships with a new password confirmation feature. This feature allows you to attach a password.confirm middleware to routes where you want a user to re-confirm their password. Considering your code your route will look like below.

Route::get('/secret', 'DiariesController@index')->middleware(['auth', 'verified','password.confirm']);

If you attempt to access the route, you will be prompted to confirm your password, similar to what you may have seen on other applications like GitHub. For more info you can visit this

Thanks

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I perform a `git pull` without re-entering my SSH password?

Laravel Password & Password_Confirmation Validation

How to translate routes in Laravel?

disable web middleware for specific routes in laravel 5.2

Require SSL Client Certificate only for specific routes or controllers

Avoid re-entering user/email and password with WebDriverIO in login form

Password confirmation in laravel

How to require admin confirmation of registered users with AWS Cognito?

How to redirect the user to the url after the password confirmation?

Laravel - Rate Limiting specific API routes

Disable Cookies on Specific Routes - Laravel 5.7

How to make laravel to look for admin model while forget password entering a link?

How to fix my password validation rule during confirmation of re-type during sign-up?

How to remove password confirmation field in django UserCreationForm

How to require confirmation for git reset --hard?

How to switch users without entering password

Laravel Confide ( Ardent )password confirmation works on save but not on update

Laravel 4 - Ardent - The password confirmation does not match

How to go to a specific user's record after entering username/password in a login form

Devise: How can I send the confirmable email but not require confirmation by while

How to send password with confirmation email (PHP)

Require previous password as validation to save settings in Laravel

How to make sure a user is entering a specific string?

Laravel Routes not working like they're supposed to

Require Confirmation on Form Submission

password confirmation rules in laravel failed

Laravel routes not working for forget password

Show Laravel resources API for only specific routes

How to Reset Password without entering email field