Method: ROTP::TOTP#verify
- Defined in:
- lib/rotp/totp.rb
#verify(otp, drift_ahead: 0, drift_behind: 0, after: nil, at: Time.now) ⇒ Integer?
Verifies the OTP passed in against the current time OTP and adjacent intervals up to drift. Excludes OTPs from after and earlier. Returns time value of matching OTP code for use in subsequent call.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rotp/totp.rb', line 39 def verify(otp, drift_ahead: 0, drift_behind: 0, after: nil, at: Time.now) timecodes = get_timecodes(at, drift_behind, drift_ahead) timecodes = timecodes.select { |t| t > timecode(after) } if after result = nil timecodes.each do |t| result = t * interval if super(otp, generate_otp(t)) end result end |