wayhood/googleauthenticator

Google Authenticator 2-factor authentication

dev-master 2014-12-01 02:02 UTC

This package is auto-updated.

Last update: 2024-11-07 17:47:54 UTC


README

Google Authenticator 2-factor authentication

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist wayhood/googleauthenticator "*"

or add

"wayhood/googleauthenticator": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by :

use wh/googleauthenticator/GoogleAuthenticator';

$ga = new GoogleAuthenticator();

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

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

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

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