-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgenerate_qr_code.js
More file actions
29 lines (25 loc) · 793 Bytes
/
generate_qr_code.js
File metadata and controls
29 lines (25 loc) · 793 Bytes
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
const speakeasy = require("speakeasy");
const QRCode = require("qrcode");
// Generate a secret key
const secret = speakeasy.generateSecret({ length: 20 });
// Function to generate a QR code URL for Google Authenticator
function generateQRCodeURL() {
return new Promise((resolve, reject) => {
QRCode.toDataURL(secret.otpauth_url, (err, dataURL) => {
if (err) {
reject(err);
} else {
resolve(dataURL);
}
});
});
}
// Generate and display the QR code URL
generateQRCodeURL()
.then((dataURL) => {
console.log("Scan the QR code with the Google Authenticator app:");
console.log(dataURL);
})
.catch((err) => {
console.error("Error generating QR code:", err);
});