-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqr_code.php
49 lines (38 loc) · 1.4 KB
/
qr_code.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
// qr_code.php
require_once "assets/config/config.php";
require_once "vendor/autoload.php";
use PhotoTech\{
ErrorHandler,
Database,
};
use PragmaRX\Google2FA\Google2FA;
use chillerlan\QRCode\{QRCode, QROptions};
// Create an ErrorHandler instance
$errorHandler = new ErrorHandler();
// Set the exception handler to use the ErrorHandler instance
set_exception_handler([$errorHandler, 'handleException']);
// Create a Database instance and establish a connection
$database = new Database();
$pdo = $database->createPDO();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
// Instantiate Google2FA object
$google2fa = new Google2FA();
// Generate the secret key
$secret = $google2fa->generateSecretKey();
// Generate the QR code URL
$qrCodeUrl = $google2fa->getQRCodeUrl('Photo Tech Guru Authentication', $email, $secret);
// Configure the chillerlan/php-qrcode library
$options = new QROptions([
'version' => 9,
'outputType' => QRCode::OUTPUT_MARKUP_SVG,
'eccLevel' => QRCode::ECC_L,
]);
// Instantiate the chillerlan/php-qrcode object
$qrCode = new QRCode($options);
// Generate the QR code SVG markup
$qrCodeSVG = $qrCode->render($qrCodeUrl);
// Return the secret key and the QR code SVG markup
echo json_encode(['secret' => $secret, 'qrCodeSVG' => $qrCodeSVG]);
}