Module: SimplePasswordAuthentication::ModelMethods::User::ClassMethods

Defined in:
lib/simple_password_authentication/model_methods.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(username, password) ⇒ Object

Find a user using a username and password Returns the user if successful, false otherwise



56
57
58
59
60
61
62
# File 'lib/simple_password_authentication/model_methods.rb', line 56

def authenticate(username, password)
  if user = find_by_username(username)
    if user.correct_password?(password)
      user
    end
  end
end

#generate_saltObject

Generate a random salt value



50
51
52
# File 'lib/simple_password_authentication/model_methods.rb', line 50

def generate_salt
  Digest::SHA1.hexdigest(Time.now.to_f.to_s)
end

#hash_password(pw, salt) ⇒ Object

Hashes a password using a salt value



45
46
47
# File 'lib/simple_password_authentication/model_methods.rb', line 45

def hash_password(pw, salt)
  Digest::SHA1.hexdigest(salt+pw)
end