PHP code example of mkd / laravel-otp

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

    

mkd / laravel-otp example snippets


use MKD\LaravelOTP\LaravelOTP;

$secret = 'WSRNGQX4J57FL2POVHDAMBI6ZTK3CYUE'; // Base32 encoded secret
$otpService = LaravelOTP::make($secret);

// Generate current OTP
$currentOTP = $otpService->now();
echo "Current OTP: $currentOTP\n";

// Verify the OTP
$isValid = $otpService->verifyTOTP($currentOTP);
echo $isValid ? "OTP is valid!" : "OTP is invalid!";

use MKD\LaravelOTP\LaravelOTP;

$otpService = LaravelOTP::make('your-secret-key');

$otp = $otpService->now();

$otp = $otpService->last();

$otp = $otpService->next();

$otp = $otpService->at(-1); // Last TOTP
$otp = $otpService->at(1);  // Next TOTP

$secretKey = $otpService->generateSecretKey();

$otp = $otpService->atCounter(1); // OTP for counter 1

$isValid = $otpService->verifyTOTP('123456'); // Validate TOTP

$isValid = $otpService->verifyHOTP('123456', 1); // Validate HOTP for counter 1

$label = '[email protected]';
$issuer = 'YourAppName';
$otpUrl = $otpService->generateUrl($label, $issuer);
echo "OTP Auth URL: $otpUrl" // otpauth://totp/Name?secret=WSRNGQX4J57FL2POVHDAMBI6ZTK3CYUE&issuer=APP;