Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'digest/sha2'
- class User < ActiveRecord::Base
- validates_uniqueness_of :username
- def password=(pass)
- salt = [Array.new(6){rand(256).chr}.join].pack("m").chomp
- self.password_salt = salt
- self.password_hash = Digest::SHA256.hexdigest(pass salt)
- end
- def self.authenticate(username, password)
- user = User.find(:first, :conditions => ['username = ?', username])
- #check the user/pass
- if user.blank? or Digest::SHA256.hexdigest(password user.password_salt) != user.password_hash
- return nil
- else
- return user
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement