diff --git a/lib/active_model/one_time_password.rb b/lib/active_model/one_time_password.rb index 86c19e3..42d1681 100644 --- a/lib/active_model/one_time_password.rb +++ b/lib/active_model/one_time_password.rb @@ -49,7 +49,7 @@ def authenticate_otp(code, options = {}) result = hotp.verify(code, otp_counter) if result && options[:auto_increment] self.otp_counter += 1 - save if respond_to?(:new_record?) && !new_record? + save if respond_to?(:changed?) && !new_record? end result else @@ -66,7 +66,7 @@ def otp_code(options = {}) if otp_counter_based if options[:auto_increment] self.otp_counter += 1 - save if respond_to?(:new_record?) && !new_record? + save if respond_to?(:changed?) && !new_record? end ROTP::HOTP.new(otp_column, digits: otp_digits).at(self.otp_counter) else