# 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