PHP code example of madmikeyb / reauthenticate

1. Go to this page and download the library: Download madmikeyb/reauthenticate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

madmikeyb / reauthenticate example snippets


Route::group(['middleware' => ['auth','reauthenticate']], function () {

    Route::get('user/payment', function () {
        // Needs to re-enter password to see this
    });

});

protected $routeMiddleware = [
    // ...
    'reauthenticate'         => \Mpociot\Reauthenticate\Middleware\Reauthenticate::class,
    // ...
];



namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Mpociot\Reauthenticate\Reauthenticates;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */
    use AuthenticatesUsers, Reauthenticates;

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => ['logout','getReauthenticate','postReauthenticate'] ]);
    }

// Reauthentication routes
Route::namespace('Auth')->group(function () {
    Route::get('auth/reauthenticate', 'LoginController@getReauthenticate');
    Route::post('auth/reauthenticate', 'LoginController@postReauthenticate');
});

return [
    /*
    |--------------------------------------------------------------------------
    | Reauthenticate
    |--------------------------------------------------------------------------
    */
    
    /**
     * The URL to redirect to after re-authentication is successful.
     */
    'reauthenticate_url' => '/custom-url',

    /**
     * The key to use as your re-authentication session key.
     */
    'reauthenticate_key' => 'custom-reauthentication-key',

    /**
     * The time (in minutes) that the user is allowed to access the protected area 
     * before being prompted to re re-authenticate.
     */
    'reauthenticate_time' => 30,
];