PHP code example of neto737 / googleauthenticator

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

    

neto737 / googleauthenticator example snippets




$ga = new \neto737\GoogleAuthenticator;

$secret = $ga->createSecret();
echo "Secret is: " . $secret . PHP_EOL . PHP_EOL;

$qrCodeUrl = $ga->getQRCodeGoogleUrl('Blog', $secret);
echo "Google Charts URL for the QR-Code: ".$qrCodeUrl . PHP_EOL . PHP_EOL;

$oneCode = $ga->getCode($secret);
echo "Checking Code '$oneCode' and Secret '$secret': ";

$checkResult = $ga->verifyCode($secret, $oneCode, 2); // 2 = 2*30sec clock tolerance
if ($checkResult) {
    echo 'OK';
} else {
    echo 'FAILED';
}