Class: Debci::Key
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Debci::Key
- Defined in:
- lib/debci/key.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
Class Method Summary collapse
- .authenticate(key) ⇒ Object
-
.encrypt(key) ⇒ Object
Since the key being encrypted is random, there is no point is using salts to protect against rainbow tables.
- .reset!(user) ⇒ Object
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
10 11 12 |
# File 'lib/debci/key.rb', line 10 def key @key end |
Class Method Details
.authenticate(key) ⇒ Object
22 23 24 25 |
# File 'lib/debci/key.rb', line 22 def self.authenticate(key) entry = find_by(encrypted_key: encrypt(key)) entry&.user || nil end |
.encrypt(key) ⇒ Object
Since the key being encrypted is random, there is no point is using salts to protect against rainbow tables. So let’s just use a good old SHA1 hash.
30 31 32 |
# File 'lib/debci/key.rb', line 30 def self.encrypt(key) Digest::SHA1.hexdigest(key) end |
.reset!(user) ⇒ Object
17 18 19 20 |
# File 'lib/debci/key.rb', line 17 def self.reset!(user) find_by(user: user)&.destroy create!(user: user) end |