Class: QuoVadis::RecoveryCode

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/quo_vadis/recovery_code.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generate_codeObject

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