PHPGangsta / GoogleAuthenticator

PHP class to generate and verify Google Authenticator 2-factor authentication
http://phpgangsta.de/4376
BSD 2-Clause "Simplified" License
2.26k stars 699 forks source link

i cant key the code correctly #31

Open roderisland opened 8 years ago

roderisland commented 8 years ago

hi sir, my timezone is gmt+8, i modify the timezone and pass the param to $timeslice, but i keep keyin the code and keep cant match the code with my phone, anything i did it wrong? thank you.

<?php

require_once '../PHPGangsta/GoogleAuthenticator.php';

$timezone = 8; //(GMT +8:00) Asia $unixtimestamp = time() + 3600*$timezone;

$ga = new PHPGangsta_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,$unixtimestamp); echo "Checking Code '$oneCode' and Secret '$secret':\n\n";

$code=$_POST['txtCode']; echo $code."
";

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

?>

PHPGangsta commented 8 years ago

I guess the problem is that you give the current timestamp to the methods getCode() and verifyCode(). You need to give it the "time slice", which is a timestamp devided by 30... Maybe it works then?