Skip to content

Commit 7da1f0c

Browse files
committed
fix after second issue, and make the check time constant
1 parent d9be47a commit 7da1f0c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/rotp/totp.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@ def now
3939
def verify(otp, drift_ahead: 0, drift_behind: 0, after: nil, at: Time.now)
4040
now = timeint(at)
4141

42+
after += 1 if after # we need to skip time <= after
4243
timecode_start = timecode([now - drift_behind, after].compact.max)
4344
timecode_end = timecode(now + drift_ahead)
4445

46+
result = nil
47+
4548
timecode_start.upto(timecode_end) do |t|
46-
return t * interval if super(otp, generate_otp(t))
49+
result = t * interval if super(otp, generate_otp(t))
4750
end
4851

49-
nil
52+
result
5053
end
5154

5255
# Returns the provisioning URI for the OTP

0 commit comments

Comments
 (0)