Hey i want to check if the key in the textfield is the same as on the mobilephone from the qrCode. But something is not working. In the two functions above i am generating an QR code and try to check if the inputfield value is the same as the code on the phone. But the verified returns always false. Can anyone help me?
var QRCode = require('qrcode');
var speakeasy = require("speakeasy");
var secret;
var base32secret;
function generateQRCode(){
secret = speakeasy.generateSecret({
name: "M183 Projekt"
});
base32secret = secret.base32;
QRCode.toDataURL(secret.otpauth_url, function(err, data_url) {
console.log(data_url);
var qrcodeimage = document.getElementById("qrcode");
qrcodeimage.style.display = "flex";
qrcodeimage.src = data_url;
});
}
function isKeyValid(){
var userToken = document.getElementById("keyinput").`enter code here`value;
var base32UserToken = userToken.base32;
var verified = speakeasy.totp.verify({
secret: base32secret,
encoding: 'base32',
token: base32UserToken,
window: 5
});
console.log(userToken);
console.log(base32UserToken);
console.log(base32secret);
console.log(verified);`enter code here`
}