PHP code example of nocksapp / google2fa-laravel

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

    

nocksapp / google2fa-laravel example snippets


PragmaRX\Google2FALaravel\ServiceProvider::class,

'Google2FA' => PragmaRX\Google2FALaravel\Facade::class,

php artisan vendor:publish --provider=PragmaRX\\Google2FALaravel\\ServiceProvider

use Google2FA;

return Google2FA::generateSecretKey();

$google2fa = app('pragmarx.google2fa');

return $google2fa->generateSecretKey();

protected $routeMiddleware = [
    ...
    '2fa' => \PragmaRX\Google2FALaravel\Middleware::class,
];

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

/**
 * One Time Password View
 */
'view' => 'google2fa.index',

/**
 * One Time Password request input name
 */
'otp_input' => 'one_time_password',

/**
* Lifetime in minutes.
* In case you need your users to be asked for a new one time passwords from time to time.
*/

'lifetime' => 0, // 0 = eternal

/**
 * Renew lifetime at every new request.
 */

'keep_alive' => true,

Google2FA::logout();

use PragmaRX\Google2FALaravel\Support\Authenticator;

(new Authenticator(request()))->logout();