Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Manager < ActiveRecord::Base
- validates_presence_of :password
- validates_presence_of :email
- validates_email_format_of :email
- attr_accessor :password_confirmation
- validates_confirmation_of :password
- def self.verify(email, password)
- Manager.find( :first, :conditions => { :email => email, :password => password } )
- end
- def self.authenticate(email, password)
- user = self.find_by_name(email)
- if user
- expected_password = encrypted_password(password, user.salt)
- if user.hashed_password != expected_password
- user = nil
- end
- end
- user
- end
- def password
- @password
- end
- def password=(pwd)
- @password = pwd
- return if pwd.blank?
- create_new_salt
- self.hashed_password = Manager.encrypted_password(self.password, self.salt)
- end
- private
- def self.encrypted_password(password, salt)
- string_to_hash = password + "scramble" + salt
- Digest::SHA1.hexdigest(string_to_hash)
- end
- def create_new_salt
- self.salt = self.object_id.to_s + rand.to_s
- end
- end
Add Comment
Please, Sign In to add comment