Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User < ActiveRecord::Base
- validates_uniqueness_of :handle, :message => "already exists"
- validates_length_of :handle, :within => 1..10
- validates_length_of :fname, :within => 1..15
- validates_length_of :lname, :within => 1..15
- def self.authenticate(handle, password)
- user_salt = User.find_by_password_salt(:conditions => ["handle = ?", handle])
- user = User.find(:conditions => ["handle = ? AND password_hash = ?", handle, Digest::SHA512.hexdigest(password + user_salt)])
- return user
- end
- # Generate random salt and encrypt with SHA512. Store password_salt and password_hash into user object.
- def password=(pass)
- salt = [Array.new(6){rand(256).chr}.join].pack("m").chomp
- self.password_salt, self.password_hash = salt, Digest::SHA512.hexdigest(pass + salt)
- end
- end
Add Comment
Please, Sign In to add comment