Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'digest/sha1'
- class User < ActiveRecord::Base
- before_validation :encrypt_password
- def encrypt_password
- self.salt = generate_salt
- self.password = Digest::SHA1.hexdigest(self.password + self.salt)
- end
- def generate_salt
- characters = ""
- characters << "abcdefghijklmnopqrstuvwxyz"
- characters << "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- characters << "0123456789"
- salt = ""
- 10.downto(1) {salt << characters[rand(62)]}
- return salt
- end
- end
Add Comment
Please, Sign In to add comment