嘿,我想检查文本字段中的密钥是否与 qrCode 中的手机相同。但是有些东西不起作用。在上面的两个函数中,我正在生成一个二维码并尝试检查输入字段值是否与手机上的代码相同。但是经过验证的返回总是错误的。谁能帮我?
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`
}