PHP code example of tekintian / google-authenticator
1. Go to this page and download the library: Download tekintian/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/ */
tekintian / google-authenticator example snippets
$ga = new \tekintian\GoogleAuthenticator()
$secret = $ga->createSecret();
echo "Secret is: ".$secret."\n\n";
$qr = $ga->getQRCode('Tekin', $secret);
echo "Default return the base64 QR-Code img: ".$qr."\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 可以有1分钟的时间误差
$checkResult = $ga->verifyCode($secret, $oneCode, 0); // 不允许有时间误差
if ($checkResult) {
echo 'OK';
} else {
echo 'FAILED';