Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

118
Vistas
2fa authentication with html and javascript

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`

}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda