PHP code example of xsuchy09 / googleauthenticator

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

    

xsuchy09 / googleauthenticator example snippets



= new GoogleAuthenticator();

$name = 'suchy';
$secret = $ga->createSecret();
$title = 'WAMOS.cz';

echo sprintf('Name is: %s', $name) . PHP_EOL;
echo sprintf('Secret is: %s', $secret) . PHP_EOL;
echo sprintf('Title is: %s', $title) . PHP_EOL . PHP_EOL;

$dataToRender = $ga->getOtpAuthLink($name, $secret, $title); // or getDataToRender method - just alis
echo sprintf('Data to render: %s', $dataToRender) . PHP_EOL . PHP_EOL;

// don't use this, don't share you security with third parties
$qrCodeUrl = $ga->getQRCodeGoogleUrl($name, $secret, $title);
echo sprintf('Google Charts URL for the QR-Code: %s', $qrCodeUrl) . PHP_EOL . PHP_EOL;

$oneCode = $ga->getCode($secret);
echo sprintf('Checking Code %s and Secret %s:', $oneCode, $secret) . PHP_EOL;

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