PHP code example of chillerlan / 2fa-qrcode-bundle
1. Go to this page and download the library: Download chillerlan/2fa-qrcode-bundle 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/ */
chillerlan / 2fa-qrcode-bundle example snippets
use chillerlan\TwoFactorQRCode\TwoFactorQRCode;
$options = [
'secret_length' => 128,
'adjacent' => 2,
];
$twoFactorQRCode = new TwoFactorQRCode($options);
$newSecret = $twoFactorQRCode->createSecret();
$qrcode = $twoFactorQRCode->getQRCode('label', 'issuer');
$backup = $twoFactorQRCode->createBackupCode($counterValue);
if($twoFactorQRCode->verifyOTP($newOTP)){
echo 'yay! do not forget to save your backup code!';
}
$twoFactorQRCode->setSecret($userSecret);
if($twoFactorQRCode->verifyOTP($OTP)){
// do stuff...
// redirect
header('Location: ...');
}