Google Authenticator 2-factor authentication
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';
}