Skip to content

Instantly share code, notes, and snippets.

@jgaskins
Created April 9, 2013 17:55
Show Gist options
  • Save jgaskins/5347861 to your computer and use it in GitHub Desktop.
Save jgaskins/5347861 to your computer and use it in GitHub Desktop.
Hashing Passwords with Virtus as a Service
require 'bcrypt'
class HashedPassword < Virtus::Attribute::String
class Hashed < Virtus::Attribute::Writer::Coercible
def coerce(value)
BCrypt::Password.create(value)
end
end
lazy true # No idea what this does. I found it in spec/integration/custom_attributes_spec.rb
def self.writer_class(*)
Hashed
end
end
require 'virtus'
require 'hashed_password'
class User
include Virtus
attribute :email, String
attribute :password, HashedPassword
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment