Two-step verification with php sonata-Project/google-authenticator not working

119 Views Asked by At

I have this code but it is not working.

Using either Microsfot or Google Authenticator on an iPhone, I scan the code to add the account to the App. Then, generate some codes but not working, nor with a pre-made secret key or generating one on the fly.

What gives?

<?php 

include_once 'vendor/sonata-project/google-authenticator/src/FixedBitNotation.php';
include_once 'vendor/sonata-Project/google-authenticator/src/GoogleAuthenticatorInterface.php';
include_once 'vendor/sonata-project/google-authenticator/src/GoogleAuthenticator.php';
include_once 'vendor/sonata-project/google-authenticator/src/GoogleQrUrl.php';

$g = new \Google\Authenticator\GoogleAuthenticator();
$secret = 'JHGDJ67HYTR398TR';
//$secret = $g->generateSecret();

$mail = "[email protected]";

$qrAUT =  \Sonata\GoogleAuthenticator\GoogleQrUrl::generate($mail, $secret, 'TEST SITE'); 
 echo '<img src="'.$qrAUT.'" /><br><br>';
?>

<form action="">
  <label for="fname">Code:</label><br>
  <input type="text" id="code" name="code" value=""><br>
  <input type="submit" value="Submit">
</form> 

<?
$code = $_GET['code'];

if($g->checkCode($secret, $code)){
    echo $code . ' Authorized!';
}
else{
    echo $code . ' Incorrect or expired code!';
}
?>
0

There are 0 best solutions below