totp debugging
This commit is contained in:
parent
c149b84db0
commit
f248550a6b
1 changed files with 24 additions and 1 deletions
|
|
@ -199,8 +199,31 @@ defmodule Towerops.Accounts do
|
|||
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
|
||||
current_time = System.system_time(:second)
|
||||
|
||||
# NimbleTOTP.valid? by default checks current time +/- 1 time step (30s)
|
||||
NimbleTOTP.valid?(secret, code)
|
||||
result = NimbleTOTP.valid?(secret, code)
|
||||
|
||||
if !result do
|
||||
require Logger
|
||||
# Log detailed debugging info when TOTP fails
|
||||
expected_code_current = NimbleTOTP.verification_code(secret, time: current_time)
|
||||
expected_code_prev = NimbleTOTP.verification_code(secret, time: current_time - 30)
|
||||
expected_code_next = NimbleTOTP.verification_code(secret, time: current_time + 30)
|
||||
|
||||
Logger.info("TOTP verification failed",
|
||||
provided_code: code,
|
||||
provided_code_length: String.length(code),
|
||||
expected_code_current: expected_code_current,
|
||||
expected_code_prev: expected_code_prev,
|
||||
expected_code_next: expected_code_next,
|
||||
current_unix_time: current_time,
|
||||
current_datetime: DateTime.from_unix!(current_time),
|
||||
secret_length: String.length(secret)
|
||||
)
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue