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

137
Views
One time password generation in express js

I am trying to generate OTP in express js using speakeasy https://www.npmjs.com/package/speakeasy.

Here is the sample code i've tried

var speakeasy = require('speakeasy');
        var secret = speakeasy.generateSecret({length:32});

        //generate token
        var code = speakeasy.totp({
            secret:secret.base32,
            encoding: 'base32',
            step:300,
            window:100,
            counter:123
        });

        //verify token
        var verified = speakeasy.totp.verify({
            secret:secret.base32 ,
            encoding: 'base32',
            token: code
        });

When verify the token console.log(verified) always return false.

I've followed this github link https://github.com/speakeasyjs/speakeasy/issues/52 but it didn't help

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

I don't know about speakeasy, but we've successfully used notp in our project to generate one-time passwords we use with Express, maybe this might help : https://www.npmjs.com/package/notp

about 4 years ago · Santiago Trujillo Report

0

module.exports = (num = 4) => {
    return Math.random().toFixed(num).substr(`-${num}`)
}

OTP: 9749

about 4 years ago · Santiago Trujillo Report

0

Add step value given while generating token for verify.

var verified = speakeasy.totp.verify({
        secret:secret.base32 ,
        encoding: 'base32',
        token: code,
        step: 300
    });
about 4 years ago · Santiago Trujillo Report
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!