PHP code example of hosseinhezami / totp-authenticator

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

    

hosseinhezami / totp-authenticator example snippets

bash
use HosseinHezami\TotpAuthenticator\Authenticator;

// Generate a new secret key
$secret = Authenticator::createSecret();

// Generate a TOTP code
$code = Authenticator::generateCode($secret);

// Verify the code
$isValid = Authenticator::verifyCode($secret, $code);
var_dump($isValid); // true

// Generate a QR code URL for Google Authenticator
$qrCodeUrl = Authenticator::generateQrCodeUrl("[email protected]", $secret, "MyApp");
echo $qrCodeUrl;