PHP code example of sanjay-np / laravel-authenticator
1. Go to this page and download the library: Download sanjay-np/laravel-authenticator 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/ */
sanjay-np / laravel-authenticator example snippets
use LaravelAuthenticator\LaravelAuthenticator;
$auth = app(\LaravelAuthenticator\LaravelAuthenticator::class);
// Create a secret for a client (e.g., user id)
$record = $auth->generateClientSecret(clientId: 123, label: 'My Device');
// Get current TOTP code
$code = $auth->getCurrentCode($record->secret);
// Verify a code
$isValid = $auth->verifyCode($record->secret, $code);
// Verify by client id via model lookup
$isValid = $auth->verifyTotpCode(123, $code);
// Data for UI display (timer, progress, etc.)
$data = $auth->getClientTotpDisplayData($record->id);
use LaravelAuthenticator\Facades\LaravelAuthenticator;
$secret = LaravelAuthenticator::generateSecret();