PHP code example of hanhan / google-authenticator

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

    

hanhan / google-authenticator example snippets



gle = new GoogleAuthenticator();
$secret = $google->createSecret();
echo "Secret is: ".$secret."\n\n";

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

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

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