Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'digest/sha2'
- class User < ActiveRecord::Base
- validates_uniqueness_of :username
- validates_presence_of :username, :email, :name
- has_many :sendlists
- has_many :attachments
- has_many :looks
- has_many :message_templates
- attr_accessor :password
- def password=(pass)
- salt = [Array.new(6){rand(256).chr}.join].pack("m").chomp
- self.password_salt, self.password_hash =
- salt, Digest::SHA256.hexdigest(pass + salt)
- end
- def self.authenticate(username, password)
- user = User.find(:first, :conditions => ['username = ?', username])
- if user.blank? ||
- Digest::SHA256.hexdigest(password + user.password_salt) != user.password_hash
- raise "Username or password invalid"
- end
- end
- end
Add Comment
Please, Sign In to add comment