[GH-ISSUE #103] verifyKey returning false everytime. #47

Closed
opened 2026-02-25 20:32:16 +03:00 by kerem · 1 comment
Owner

Originally created by @gautam-jha on GitHub (Apr 9, 2018).
Original GitHub issue: https://github.com/antonioribeiro/google2fa/issues/103

This is my code, i am unable to figure out why $vaild is returning false every time.

<?php

$user = array('email' =>'user@gmail.com','google2fa_secret'=>$google2fa->generateSecretKey(16));

$google2fa->setAllowInsecureCallToGoogleApis(true);

$google2fa_url = $google2fa->getQRCodeGoogleUrl(
    'Redipay.com',
    $user['email'],
    $user['google2fa_secret']
);

//print_r($user);
/// and in your view:

echo '<img src="'.$google2fa_url.'" alt="">';


//print_r($_POST);
if($_POST['Verify']){

echo 'secret Submitted by you' . $_POST['secret'];

$secret = $_POST['secret'];

$valid = $google2fa->verifyKey($user['google2fa_secret'], $secret, 8);

if($valid){
	
	echo 'code is valid';

}else{
	echo "Please provide Correct information.";
}

}


?>


<form action="" method="POST" >
	<input type="text" name="secret" class="form-control col-sm-6" placeholder="enter your secret code" />
	<button type="submit" name="Verify" value="Verify">Verify</button>
</form>
Originally created by @gautam-jha on GitHub (Apr 9, 2018). Original GitHub issue: https://github.com/antonioribeiro/google2fa/issues/103 This is my code, i am unable to figure out why $vaild is returning false every time. ```` <?php $user = array('email' =>'user@gmail.com','google2fa_secret'=>$google2fa->generateSecretKey(16)); $google2fa->setAllowInsecureCallToGoogleApis(true); $google2fa_url = $google2fa->getQRCodeGoogleUrl( 'Redipay.com', $user['email'], $user['google2fa_secret'] ); //print_r($user); /// and in your view: echo '<img src="'.$google2fa_url.'" alt="">'; //print_r($_POST); if($_POST['Verify']){ echo 'secret Submitted by you' . $_POST['secret']; $secret = $_POST['secret']; $valid = $google2fa->verifyKey($user['google2fa_secret'], $secret, 8); if($valid){ echo 'code is valid'; }else{ echo "Please provide Correct information."; } } ?> <form action="" method="POST" > <input type="text" name="secret" class="form-control col-sm-6" placeholder="enter your secret code" /> <button type="submit" name="Verify" value="Verify">Verify</button> </form> ````
kerem closed this issue 2026-02-25 20:32:16 +03:00
Author
Owner

@nztim commented on GitHub (Apr 9, 2018):

Because the secret key given to the user is not the same as the one it is verified against.
You'll need to save the secret key given to the user so you can verify the user submission against it.

<!-- gh-comment-id:379919338 --> @nztim commented on GitHub (Apr 9, 2018): Because the secret key given to the user is not the same as the one it is verified against. You'll need to save the secret key given to the user so you can verify the user submission against it.
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/google2fa#47
No description provided.