composer require pragmarx/google2fa
composer require bacon/bacon-qr-code
Last active
March 20, 2018 10:23
-
-
Save binzram/e63c54e5f6b1752e4f7c75ef58da4b5c to your computer and use it in GitHub Desktop.
PHP Google Auth 2FA (student example, bbc)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use PragmaRX\Google2FA\Google2FA; | |
$google2fa = new Google2FA(); | |
// save userSecret in db | |
$userSecret = $google2fa->generateSecretKey(); | |
// link to img src | |
$inlineUrl = $google2fa->getQRCodeInline( | |
'TestOrganisation', | |
'test@organisation.com', | |
$secret | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use PragmaRX\Google2FA\Google2FA; | |
$google2fa = new Google2FA(); | |
// saved userSecret from db | |
$userSecret = $user->get2faSecret(); | |
// entered code | |
$validationCode = $input->getData(); | |
// only current code is valid | |
$numberOfAllowedByGoneCodes = 0; | |
// (in)valid | |
var_dump( | |
$google2fa->verifyKey( | |
$userSecret, | |
$validationCode, | |
$numberOfAllowedByGoneCodes | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment