1. Go to this page and download the library: Download kohaku1907/lara2step 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/ */
kohaku1907 / lara2step example snippets
return [
'default_channel' => 'email', // email, sms
'table_name' => 'two_step_auths', // table name
'code_length' => 4, // code length
'numeric_code' => false, // numeric code only
'confirm_key' => '_2fa', // session key name
'timeout' => 300, // timeout of verifed session in minutes
'max_attempts' => 5, // max attempts
'exceed_countdown_minutes' => 1440, // exceed countdown in minutes
'resend_code_seconds' => 60, // resend code in seconds
];
use Kohaku1907\Lara2step\Contracts\TwoStepAuthenticatable;
use Kohaku1907\Lara2step\TwoStepAuthentication;
class User extends Authenticatable implements TwoStepAuthenticatable {
use TwoStepAuthentication;
public function registerTwoStepAuthentication(): void
{
$this->configureForceEnable('email');
$this->configureCodeFormat(length: 4, numericCode: true);
}
}
Route::get('/dashboard', function () {
// Only verified users...
})->middleware('2step');
use Kohaku1907\Lara2step\Http\Controllers\TwoStepController;
use Illuminate\Support\Facades\Route;
Route::get('2fa-confirm', [TwoStepController::class, 'form'])
->name('2step.confirm');
Route::post('2fa-confirm', [TwoStepController::class, 'confirm']);
Route::post('2fa-resend', [TwoStepController::class, 'resend'])
->name('2step.resend');