heapsource / active_model_otp

Adds methods to set and authenticate against one time passwords (Two-Factor Authentication). Inspired in AM::SecurePassword
MIT License
769 stars 81 forks source link

TypeError when using non ASCII characters in the OTP secret key #3

Closed hkairi closed 10 years ago

hkairi commented 11 years ago

require "active_model_otp"

class User extend ActiveModel::Callbacks include ActiveModel::Validations include ActiveModel::OneTimePassword

define_model_callbacks :create attr_accessor :otp_secret_key, :email

has_one_time_password end

user = User.new user.email = 'roberto@heapsource.com' user.otp_secret_key = "anotherfakeOTPSecretKey!!" puts "Current code #{user.otp_code}"

I am having this issue everytime the OTP secret key is containing non ASCII characters or numbers

.../rotp-1.4.1/lib/rotp/base32.rb:37:in `+': nil can't be coerced into Fixnum (TypeError)

andrehjr commented 10 years ago

Latest version gives me a sane error.. a ROTP::Base32::Base32Error as expected, this could be closed I guess.

puts "Current code #{user.otp_code}" ROTP::Base32::Base32Error: Invalid Base32 Character - '!' from /Users/andrehjr/.rvm/gems/ruby-1.9.3-p327/gems/rotp-1.5.0/lib/rotp/base32.rb:46:in decode_quint' from /Users/andrehjr/.rvm/gems/ruby-1.9.3-p327/gems/rotp-1.5.0/lib/rotp/base32.rb:28:inblock in decode_block' from /Users/andrehjr/.rvm/gems/ruby-1.9.3-p327/gems/rotp-1.5.0/lib/rotp/base32.rb:28:in each_char' from /Users/andrehjr/.rvm/gems/ruby-1.9.3-p327/gems/rotp-1.5.0/lib/rotp/base32.rb:28:ineach' from /Users/andrehjr/.rvm/gems/ruby-1.9.3-p327/gems/rotp-1.5.0/lib/rotp/base32.rb:28:in map' from /Users/andrehjr/.rvm/gems/ruby-1.9.3-p327/gems/rotp-1.5.0/lib/rotp/base32.rb:28:indecode_block' from /Users/andrehjr/.rvm/gems/ruby-1.9.3-p327/gems/rotp-1.5.0/lib/rotp/base32.rb:10:in block in decode' from /Users/andrehjr/.rvm/gems/ruby-1.9.3-p327/gems/rotp-1.5.0/lib/rotp/base32.rb:9:ineach' from /Users/andrehjr/.rvm/gems/ruby-1.9.3-p327/gems/rotp-1.5.0/lib/rotp/base32.rb:9:in decode' from /Users/andrehjr/.rvm/gems/ruby-1.9.3-p327/gems/rotp-1.5.0/lib/rotp/otp.rb:49:inbyte_secret' from /Users/andrehjr/.rvm/gems/ruby-1.9.3-p327/gems/rotp-1.5.0/lib/rotp/otp.rb:26:in generate_otp' from /Users/andrehjr/.rvm/gems/ruby-1.9.3-p327/gems/rotp-1.5.0/lib/rotp/totp.rb:24:inat' from /Users/andrehjr/.rvm/gems/ruby-1.9.3-p327/gems/active_model_otp-0.0.1/lib/active_model/one_time_password.rb:31:in otp_code' from (irb):16 from /Users/andrehjr/.rvm/rubies/ruby-1.9.3-p327/bin/irb:16:in

'

robertomiranda commented 10 years ago

@andrehjr right :+1: