Class: Debci::Key

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/debci/key.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#keyObject

Returns the value of attribute key.



8
9
10
# File 'lib/debci/key.rb', line 8

def key
  @key
end

Class Method Details

.authenticate(key) ⇒ Object



20
21
22
23
# File 'lib/debci/key.rb', line 20

def self.authenticate(key)
  entry = find_by(encrypted_key: encrypt(key))
  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.



28
29
30
# File 'lib/debci/key.rb', line 28

def self.encrypt(key)
  Digest::SHA1.hexdigest(key)
end

.reset!(username) ⇒ Object



15
16
17
18
# File 'lib/debci/key.rb', line 15

def self.reset!(username)
  find_by(user: username)&.destroy
  create!(user: username)
end