Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!