Time User's code user.otp_code 00s 542851 => 154955 30s 154955 => 674074 60s 674074 => 998683 90s 998683 => another
# config/initializers/one_time_password_decorator.rb
ActiveModel::OneTimePassword::InstanceMethodsOnActivation.module_eval do
def authenticate_otp(code, options = {})
return true if backup_codes_enabled? && authenticate_backup_code(code)
if otp_counter_based
hotp = ROTP::HOTP.new(otp_column, digits: otp_digits)
result = hotp.verify(code, otp_counter)
if result && options[:auto_increment]
self.otp_counter += 1
save if respond_to?(:changed?) && !new_record?
end
result
else
totp = ROTP::TOTP.new(otp_column, digits: otp_digits)
if drift = options[:drift]
totp.verify(code, drift_behind: drift, drift_ahead: drift) # <= my change
else
totp.verify(code)
end
end
end
end