diff --git a/lib/two_factor_authentication/models/two_factor_authenticatable.rb b/lib/two_factor_authentication/models/two_factor_authenticatable.rb index d55a851..410055a 100644 --- a/lib/two_factor_authentication/models/two_factor_authenticatable.rb +++ b/lib/two_factor_authentication/models/two_factor_authenticatable.rb @@ -32,7 +32,7 @@ module Devise end def otp_code(time = Time.now) - ROTP::TOTP.new(self.otp_column).at(time) + ROTP::TOTP.new(self.otp_column).at(time, true) end def provisioning_uri(account = nil, options = {}) diff --git a/spec/lib/two_factor_authentication/models/two_factor_authenticatable_spec.rb b/spec/lib/two_factor_authentication/models/two_factor_authenticatable_spec.rb index efa8e37..014a432 100644 --- a/spec/lib/two_factor_authentication/models/two_factor_authenticatable_spec.rb +++ b/spec/lib/two_factor_authentication/models/two_factor_authenticatable_spec.rb @@ -25,7 +25,15 @@ describe Devise::Models::TwoFactorAuthenticatable, '#otp_code' do let(:time) { 1392852756 } it "should return a known result" do - expect(subject).to eq(562202) + expect(subject).to eq('562202') + end + end + + context "with a known time yielding a result with less than 6 digits" do + let(:time) { 1393065856 } + + it "should return a known result padded with zeroes" do + expect(subject).to eq('007672') end end end