Module: Authtools::Password

Includes:
Common
Defined in:
lib/authtools/password.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

salt

Class Method Details

.check(password, store) ⇒ Object

Checks the password against the stored password.

Examples

# In `store` is hash generated before (see `generate` method).
Authtools::Password.check('mysecret', store) # => true
Authtools::Password.check('fake', store)     # => false


34
35
36
37
38
39
40
41
42
# File 'lib/authtools/password.rb', line 34

def self.check(password, store)
  hash = self.get_hash(store)
  salt = self.get_salt(store)
  if self.hash(password, salt) == hash
    true
  else
    false
  end
end

.generate(password) ⇒ Object

Generates a new salt and rehashes the password. Returns mixed hash.

Examples

store = Authtools::Password.generate('mysecret') 
  # => "f7d8f299e342168b7a8b0aeece32e090c4acced13a6bd7f2b26fc
  # 88251f550943820d190df00a87d20b7bc00cee332c48f9c4953793837
  # 2a6c4fbcbe5d3944ccr1x6DlrfTf6OUrwl6ohoivxN2fAQiblav1sLyd9
  # z7PFaQgQH3XxTA0BuMAbFRmMM"


15
16
17
18
19
# File 'lib/authtools/password.rb', line 15

def self.generate(password)
  salt = Authtools::Common.salt
  hash = self.hash(password, salt)
  self.store(hash, salt)
end

Instance Method Details

#new(password) ⇒ Object

Alias for generate method



23
24
25
# File 'lib/authtools/password.rb', line 23

def new(password)
  generate(password)
end