PHP code example of stealthfirems / laravel-otp-module

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

    

stealthfirems / laravel-otp-module example snippets


use StealthFireMS\LaravelOTPModule\Otp;


generate_otp($user_identifier);

validate_otp($user_identifer, $otp_token);

generate_otp('[email protected]');

validate_otp('[email protected]', '123456');

protected function schedule(Schedule $schedule)
{
    $schedule->command('otp:clean')->daily();
}

return [
    'TOTP_SECRET_LENGTH' => env('TOTP_SECRET_LENGTH', 32),
    'TOTP_PERIOD' => env('TOTP_PERIOD', 60),
    'TOTP_DIGITS' => env('TOTP_DIGITS', 6),
];

use StealthFireMS\LaravelOTPModule\Totp;

// Generate and persist a TOTP secret for a user
$totp = new Totp();
$response = $totp->generate_totp($user_id, $totp_name); // $totp_name is optional

// Validate a TOTP code for a user
$response = $totp->validate_totp($user_id, $totp_code);

// Generate and store a TOTP secret for user ID 89, named "Bitwarden"
$response = $totp->generate_totp(89, 'Bitwarden');
/*
$response = (object)[
    'status' => true,
    'secret' => 'BASE32SECRET...',
    'uri' => 'otpauth://totp/...',
    'message' => 'TOTP secret generated and saved'
];
*/

// Validate a TOTP code for user
$response = $totp->validate_totp(89, '123456');
/*
$response = (object)[
    'status' => true,
    'message' => 'TOTP is valid'
];
*/
bash
php artisan migrate