Giter Club home page Giter Club logo

Comments (5)

josevalim avatar josevalim commented on August 22, 2024 2

Also, keep in mind that TOTP is periodic. You can generate a TOTP now but it is in its last minute out of 5. So I don’t think it works for what you want. You could use Phoenix.Token instead.

from nimble_totp.

wojtekmach avatar wojtekmach commented on August 22, 2024

NimbleTOTP.valid?(secret, otp, time: time, period: 300)

what is the time value that you are passing?

Could you try writing a script that reproduces the issue?

from nimble_totp.

doxmazz avatar doxmazz commented on August 22, 2024

time = System.os_time(:second)

from nimble_totp.

PJUllrich avatar PJUllrich commented on August 22, 2024

@wojtekmach @whatyouhide sorry folks, but something's off here or I'm understanding the options wrong.

I created a test script because I also ran into issues where the code stopped working unexpectedly. The full script is below, but here's what I expected, how I tested it, and what the results where:

  1. If I create a code now and verify it every second for 30 seconds, it will be invalid after exactly 30 seconds.
secret = NimbleTOTP.secret()
code = NimbleTOTP.verification_code(secret)
for _sec <- 1..60 do
  NimbleTOTP.valid?(secret, code) |> IO.inspect(label: DateTime.utc_now())
  :timer.sleep(1000)
end

-> The code stopped working at every 0s and 30s mark of the minute. So, if I created a code at 12:00:54, it would stop working at 12:01:00. Same for 12:00:24, which stopped working at 12:00:30.

  1. If I validate a code with period: 60, it will be valid for 60 seconds instead of 30s.
secret = NimbleTOTP.secret()
code = NimbleTOTP.verification_code(secret)
for _sec <- 1..90 do
  NimbleTOTP.valid?(secret, code, period: 60) |> IO.inspect(label: DateTime.utc_now())
  :timer.sleep(1000)
end

-> The very first call is false already.

  1. If I create a code with period: 60 and validate it with period: 60, it will be valid for 60s.
secret = NimbleTOTP.secret()
code = NimbleTOTP.verification_code(secret, period: 60)
for _sec <- 1..90 do
  NimbleTOTP.valid?(secret, code, period: 60) |> IO.inspect(label: DateTime.utc_now())
  :timer.sleep(1000)
end

-> The code stopped working at "random" times, but mostly on the minute or at the 30s mark. One time it stopped working on the minute after ~15s of running the test and one time it stopped 47s later (started at 12:00:37, stopped at 12:01:24), one time started at 12:00:53, stopped being valid at 12:01:00. It seems like the period-option has no effect?

My Question

My question here is basically: How can I create a code that's valid for longer than 30 seconds and does not become invalid at the 30s and 60s mark?

My use-case is that i'd like to send one-time passwords per email to a user that wants to log in. That code should be valid for 5min starting at the moment the user requests it. I thought this library would allow me to do that, but it seems it's rather focused on 2FA flows, no?

from nimble_totp.

josevalim avatar josevalim commented on August 22, 2024

It has been a while but don’t you have to pass the same period option both when generating the code and when validating it? We can probably improvise the docs around this.

from nimble_totp.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.