We Recommend

The Rails Way The Rails Way
Now, for the first time, there’s a comprehensive, authoritative guide to building production-quality software with Rails. Pioneering Rails developer Obie Fernandez and a team of experts illuminate the entire Rails API, along with the Ruby idioms, design approaches, libraries, and plug-ins that make Rails so valuable.


Posted By

winson on 04/30/07


Tagged

login textmate model


Versions (?)


Basic authenticate


Published in: Rails 


  1. def self.authenticate(email, password)
  2. user = find(:first, :conditions => ['email = ?', email])
  3. unless user.blank?
  4. if user.password_hash.nil? or Digest::SHA256.hexdigest(password + user.password_salt) == user.password_hash
  5. user.update_attributes(:last_login => Time.now.to_s(:db))
  6. user
  7. else
  8. raise AuthenticationError, "Invalid email and/or password"
  9. end
  10. else
  11. raise AuthenticationError, "Invalid email and/or password"
  12. end
  13. end

Report this snippet 

You need to login to post a comment.