Skip to content

Instantly share code, notes, and snippets.

@yosiyuki
Forked from kelhusseiny/user.rb
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yosiyuki/0dda25bb3b71e9441308 to your computer and use it in GitHub Desktop.
Save yosiyuki/0dda25bb3b71e9441308 to your computer and use it in GitHub Desktop.
before_save :encrypt_password
after_save :clear_password
def encrypt_password
if password.present?
salt = BCrypt::Engine.generate_salt
self.encrypted_password= BCrypt::Engine.hash_secret(password, salt)
end
end
def clear_password
self.password = nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment