Skip to content

Commit ddc79fe

Browse files
authored
Add a couple of notes about grace periods (#43)
1 parent a4a0152 commit ddc79fe

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

lib/nimble_totp.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ defmodule NimbleTOTP do
103103
codes through potentially-slow mediums (like SMS). In this case, consider a number of
104104
"previous codes" also valid. To do this, use the `:time` option in `valid?/3` (see the
105105
function documentation for more examples).
106+
See the [TOTP RFC](https://datatracker.ietf.org/doc/html/rfc6238#section-5.2)
107+
for security and usability implications.
106108
107109
## Preventing codes from being reused
108110
@@ -321,6 +323,9 @@ defmodule NimbleTOTP do
321323
322324
In this example by validating first against the current time, but also against
323325
30 seconds ago, we allow the _previous_ code, to be still valid.
326+
327+
A grace period can also prevent flaky tests which would occur when a code is
328+
generated right before a time boundary, then considered invalid.
324329
"""
325330
@spec valid?(binary(), String.t(), [option() | validate_option()]) :: boolean()
326331
def valid?(secret, otp, opts \\ [])

0 commit comments

Comments
 (0)