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 encrypt is random, there is no point is using salts to protect against rainbow tables.
- .reset!(username) ⇒ Object
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key
9 10 11 |
# File 'lib/debci/key.rb', line 9 def key @key end |
Class Method Details
.authenticate(key) ⇒ Object
21 22 23 24 |
# File 'lib/debci/key.rb', line 21 def self.authenticate(key) entry = self.find_by(encrypted_key: encrypt(key)) entry && entry.user || nil end |
.encrypt(key) ⇒ Object
Since the key being encrypt is random, there is no point is using salts to protect against rainbow tables. So let's just use a good old SHA1 hash.
29 30 31 |
# File 'lib/debci/key.rb', line 29 def self.encrypt(key) Digest::SHA1.hexdigest(key) end |
.reset!(username) ⇒ Object
16 17 18 19 |
# File 'lib/debci/key.rb', line 16 def self.reset!(username) self.find_by(user: username)&.destroy self.create!(user: username) end |