Skip to content

Instantly share code, notes, and snippets.

@benjamingeiger
Created April 27, 2011 20:23
Show Gist options
  • Save benjamingeiger/945113 to your computer and use it in GitHub Desktop.
Save benjamingeiger/945113 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
attr_accessor :password
before_save :encrypt_password
validates :password, :presence => { :message => "cannot be blank" }, :confirmation => true
validates :email, :presence => { :message => "cannot be blank" }, :uniqueness => true, :format => { :with => /^.+@.+\..+$/, :on => :create }
7
def encrypt_password
if password.present?
self.password_salt = BCrypt::Engine.generate_salt
self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment