Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda