PHP code example of pragmarx / google2fa-laravel

1. Go to this page and download the library: Download pragmarx/google2fa-laravel 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/ */

    

pragmarx / google2fa-laravel example snippets


Route::get('/admin', function () {
    return view('admin.index');
})->middleware(['auth', '2fa', 'throttle']);

$authenticator = app(Authenticator::class)->bootStateless($request);

if ($authenticator->isAuthenticated()) {
    // otp auth success!
}
 php
PragmaRX\Google2FALaravel\ServiceProvider::class,

'Google2FA' => PragmaRX\Google2FALaravel\Facade::class,
 php
php artisan vendor:publish --provider="PragmaRX\Google2FALaravel\ServiceProvider"
 php
$google2fa = app('pragmarx.google2fa');

return $google2fa->generateSecretKey();
 php
protected $routeMiddleware = [
    ...
    '2fa' => \PragmaRX\Google2FALaravel\Middleware::class,
];
 php
Route::get('/admin', function () {
    return view('admin.index');
})->middleware(['auth', '2fa']);
 php
/*
 * Which image backend to use for generating QR codes?
 *
 * Supports imagemagick, svg and eps
 */
'qrcode_image_backend' => \PragmaRX\Google2FALaravel\Support\Constants::QRCODE_IMAGE_BACKEND_IMAGEMAGICK,
 php
Google2FA::setQRCodeBackend('svg');
 php
/**
 * Renew lifetime at every new request.
 */

'keep_alive' => true,
 php
Google2FA::logout();
 php
protected $routeMiddleware = [
    ...
    '2fa' => \PragmaRX\Google2FALaravel\MiddlewareStateless::class,
];