Last active
November 26, 2024 20:19
-
-
Save saeedvir/19b43f0c03c29b04a9fa6d360583b3ed to your computer and use it in GitHub Desktop.
Laravel QR-Code Verification Code
This file contains hidden or 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 | |
// composer require sebastiandevs/simplethenticator | |
use Illuminate\Http\Request; | |
use src\SimpleAuthenticator; | |
use Illuminate\Support\Facades\Route; | |
Route::get('/', function () { | |
$auth = new SimpleAuthenticator(6, 'SHA1'); | |
try | |
{ | |
$secret = $auth->createSecret(); | |
} | |
catch (Exception $e) | |
{ | |
echo $e->getMessage(); | |
exit(); | |
} | |
session(['QRCODE_SECRET' => $secret]); | |
$qrCodeUrl = $auth->getQRCodeGoogleUrl($secret, config('app.url'), config('app.name')); | |
return view('qrcode',compact('qrCodeUrl')); | |
}); | |
Route::post('/verify', function (Request $request) { | |
$auth = new SimpleAuthenticator(6, 'SHA1'); | |
$secret = session('QRCODE_SECRET',null); | |
$request->validate([ | |
'code' => 'required|numeric|size:6', | |
]); | |
$oneCode = $request->get('code',null); | |
$verify2FA = $auth->verifyCode($secret, $oneCode, 2)? true: false; | |
return $verify2FA === true ? 'ok' : 'NOT OK !!'; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
qrcode.blade.php