Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

every time failstotp.verify() #81

Open
saikatharryc opened this issue Feb 26, 2017 · 4 comments
Open

every time failstotp.verify() #81

saikatharryc opened this issue Feb 26, 2017 · 4 comments
Projects

Comments

@saikatharryc
Copy link

saikatharryc commented Feb 26, 2017

[HELP WANTED]
Hi, I want to generate a token that will last for a certain time, say for 7200 second, that is two hour.
what is want to do is, it will give me false when I'm ging to verify a token two hour after generation. that is will be valid till two hour of generation.

Do I need to use verifyDelta? its every time giving me false when I'm setting time.

and my code is below to generate the token:


 var secret = speakeasy.generateSecret();
        var token = speakeasy.totp({
            secret: secret.base32,
            encoding: 'base32',
           time : 7200
              });



and here is the verify:

var verified = speakeasy.totp.verify({
          secret: secret_str,
          encoding: 'base32',
          token: req.body.unique_code,
         window: 240   //as window value 1 for each 30 secoends..
      });

@mikepb
Copy link
Collaborator

mikepb commented Feb 26, 2017 via email

@saikatharryc
Copy link
Author

yeah, i have done the same as you said, but still its failing..says false

@mikepb
Copy link
Collaborator

mikepb commented Feb 27, 2017 via email

@mikepb mikepb added this to Bugs in 3.0 Feb 28, 2017
@mikepb mikepb moved this from Bugs to Documentation in 3.0 Feb 28, 2017
@krenor
Copy link

krenor commented May 25, 2018

Even thought its kinda late, but maybe it'll still be of use to you @saikatharryc
This is my test case to validate that the token is truly invalid at the very next step mark:

  const secret = "foo"
  const step = 75
  const timestamp = Math.floor(Date.now() / 1000)
  const response = await request
    .post(url)
    .send({ secret, step })
    .expect(201)

  expect(response.body).toHaveProperty("token")
  expect(response.body.token).toHaveLength(6)

  const encoding = "base32" // Default by the route but not by the verify function
  const time = timestamp + (step - (timestamp % step)) // Move timestamp to the very first mark of the next step
  const token = response.body.token

  expect(totp.verify({
    encoding,
    secret,
    step,
    token,
  })).toBe(true)

  expect(totp.verify({
    encoding,
    secret,
    step,
    time,
    token,
  })).toBe(false)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
3.0
Documentation
Development

No branches or pull requests

3 participants