Created
April 9, 2013 17:55
-
-
Save jgaskins/5347861 to your computer and use it in GitHub Desktop.
Hashing Passwords with Virtus as a Service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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