Wednesday, 12 April 2017

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



via Jabaa

No comments:

Post a Comment