Class: QuoVadis::RecoveryCode
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- QuoVadis::RecoveryCode
- Defined in:
- app/models/quo_vadis/recovery_code.rb
Class Method Summary collapse
-
.generate_code ⇒ Object
Returns a string of length CODE_LENGTH, with two hexadecimal groups separated by a hyphen.
Instance Method Summary collapse
-
#authenticate_code(plaintext_code) ⇒ Object
Returns true and destroys this instance if the plaintext code is authentic, false otherwise.
Class Method Details
.generate_code ⇒ Object
Returns a string of length CODE_LENGTH, with two hexadecimal groups separated by a hyphen.
21 22 23 24 |
# File 'app/models/quo_vadis/recovery_code.rb', line 21 def self.generate_code group_length = (CODE_LENGTH - 1) / 2 SecureRandom.hex(group_length).insert(group_length, '-') end |
Instance Method Details
#authenticate_code(plaintext_code) ⇒ Object
Returns true and destroys this instance if the plaintext code is authentic, false otherwise.
11 12 13 |
# File 'app/models/quo_vadis/recovery_code.rb', line 11 def authenticate_code(plaintext_code) !!(destroy if super) end |