Module: PagesCore::HasOtp
- Extended by:
- ActiveSupport::Concern
- Included in:
- User
- Defined in:
- app/models/concerns/pages_core/has_otp.rb
Instance Method Summary collapse
Instance Method Details
#recovery_codes=(codes) ⇒ Object
11 12 13 14 15 |
# File 'app/models/concerns/pages_core/has_otp.rb', line 11 def recovery_codes=(codes) self.hashed_recovery_codes = codes.map do |c| BCrypt::Password.create(c, cost: 8) end end |
#use_recovery_code!(code) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'app/models/concerns/pages_core/has_otp.rb', line 17 def use_recovery_code!(code) valid_hashes = hashed_recovery_codes.select do |c| BCrypt::Password.new(c) == code end return false unless valid_hashes.any? update(hashed_recovery_codes: hashed_recovery_codes - valid_hashes) true end |