relax totp time
This commit is contained in:
parent
1ac771c7a6
commit
b13de895f7
2 changed files with 4 additions and 3 deletions
|
|
@ -196,10 +196,11 @@ defmodule Towerops.Accounts do
|
|||
Verifies a TOTP code against a secret.
|
||||
|
||||
Returns true if the code is valid within the time window, false otherwise.
|
||||
Allows for +/- 1 time step (30 seconds) to handle clock drift.
|
||||
"""
|
||||
def verify_totp(secret, code) when is_binary(secret) and is_binary(code) do
|
||||
# Allow 30 second window for time drift
|
||||
NimbleTOTP.valid?(secret, code, since: System.system_time(:second) - 30)
|
||||
# NimbleTOTP.valid? by default checks current time +/- 1 time step (30s)
|
||||
NimbleTOTP.valid?(secret, code)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
|
|||
|
|
@ -441,7 +441,7 @@ defmodule Towerops.AccountsTest do
|
|||
# Generate code for current time (should always be valid)
|
||||
code = NimbleTOTP.verification_code(secret)
|
||||
|
||||
# Verify it works with the time window check (since: -30)
|
||||
# Verify it works (checks current time +/- 1 step)
|
||||
assert Accounts.verify_totp(secret, code)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue