Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Account < ActiveRecord::Base
- validates_length_of :username, :within => 3..64
- validates_presence_of :username, :password_salt, :password_hash
- validates_uniqueness_of :username
- def password=(password)
- self.password_salt = MD5.hexdigest(rand.to_s)
- self.password_hash = MD5.hexdigest(password + password_salt)
- return nil
- end
- def self.authenticate(username, password)
- account = find(:first, :conditions => {:username => username})
- if account.password_hash != MD5.hexdigest(password + account.password_salt)
- account = nil
- end
- return account
- end
- end
Add Comment
Please, Sign In to add comment