Guest User

Untitled

a guest
Jun 15th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. class Account < ActiveRecord::Base
  2. validates_length_of :username, :within => 3..64
  3. validates_presence_of :username, :password_salt, :password_hash
  4. validates_uniqueness_of :username
  5.  
  6. def password=(password)
  7. self.password_salt = MD5.hexdigest(rand.to_s)
  8. self.password_hash = MD5.hexdigest(password + password_salt)
  9.  
  10. return nil
  11. end
  12.  
  13. def self.authenticate(username, password)
  14. account = find(:first, :conditions => {:username => username})
  15.  
  16. if account.password_hash != MD5.hexdigest(password + account.password_salt)
  17. account = nil
  18. end
  19.  
  20. return account
  21. end
  22. end
Add Comment
Please, Sign In to add comment