Browse Source

Merge pull request #31 from brissmyr/master

Pad OTP codes with less than 6 digits
master
Dmitrii Golub 11 years ago
parent
commit
2d71cf0d83
  1. 2
      lib/two_factor_authentication/models/two_factor_authenticatable.rb
  2. 10
      spec/lib/two_factor_authentication/models/two_factor_authenticatable_spec.rb

2
lib/two_factor_authentication/models/two_factor_authenticatable.rb

@ -32,7 +32,7 @@ module Devise
end end
def otp_code(time = Time.now) def otp_code(time = Time.now)
ROTP::TOTP.new(self.otp_column).at(time) ROTP::TOTP.new(self.otp_column).at(time, true)
end end
def provisioning_uri(account = nil, options = {}) def provisioning_uri(account = nil, options = {})

10
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 } let(:time) { 1392852756 }
it "should return a known result" do 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 end
end end

Loading…
Cancel
Save