Comments (5)
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.
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.
time = System.os_time(:second)
from nimble_totp.
@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:
- 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.
- 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.
- If I create a code with
period: 60
and validate it withperiod: 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.
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)
- Encoding of space in Issuer
- Patch Release? HOT 1
- Grace period for valid? HOT 6
- Spec for valid? seems wrong HOT 2
- Version tag missing for #18 ? HOT 2
- My tests fail randomly HOT 4
- Looks like the resulting code does not match google authenticator result HOT 1
- Not issue: Help using, I am Using Nimble to send Code store the string value and validate with user entered code HOT 1
- (UndefinedFunctionError) function :crypto.hmac/3 is undefined or private, use crypto:mac/4 instead HOT 1
- Default shared secret byte length HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nimble_totp.