Guest User

Untitled

a guest
Apr 11th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. class User < ActiveRecord::Base
  2. validates_uniqueness_of :handle, :message => "already exists"
  3. validates_length_of :handle, :within => 1..10
  4. validates_length_of :fname, :within => 1..15
  5. validates_length_of :lname, :within => 1..15
  6.  
  7. def self.authenticate(handle, password)
  8. user_salt = User.find_by_password_salt(:conditions => ["handle = ?", handle])
  9. user = User.find(:conditions => ["handle = ? AND password_hash = ?", handle, Digest::SHA512.hexdigest(password + user_salt)])
  10. return user
  11. end
  12.  
  13. # Generate random salt and encrypt with SHA512. Store password_salt and password_hash into user object.
  14. def password=(pass)
  15. salt = [Array.new(6){rand(256).chr}.join].pack("m").chomp
  16. self.password_salt, self.password_hash = salt, Digest::SHA512.hexdigest(pass + salt)
  17. end
  18.  
  19. end
Add Comment
Please, Sign In to add comment