lib/rotp/totp.rb in rotp-1.4.0 vs lib/rotp/totp.rb in rotp-1.4.1
- old
+ new
@@ -36,11 +36,13 @@
# and adjacent intervals up to +drift+.
# @param [String/Integer] otp the OTP to check against
# @param [Integer] drift the number of seconds that the client
# and server are allowed to drift apart
def verify_with_drift(otp, drift, time = Time.now)
- drift_intervals = drift / interval
- (-drift_intervals..drift_intervals).any? { |n| verify(otp, time + n * interval) }
+ time = time.to_i
+ times = (time-drift..time+drift).step(interval).to_a
+ times << time + drift if times.last < time + drift
+ times.any? { |ti| verify(otp, ti) }
end
# Returns the provisioning URI for the OTP
# This can then be encoded in a QR Code and used
# to provision the Google Authenticator app