Created
March 12, 2015 14:37
-
-
Save aflatter/d47a8c6ec1c38ce418ae to your computer and use it in GitHub Desktop.
SCrypt::Password attribute type for Virtus
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 'scrypt' | |
module Virtus | |
class Attribute | |
class Password < ::Virtus::Attribute | |
primitive SCrypt::Password | |
def coerce(value) | |
value ? SCrypt::Password.new(value) : nil | |
rescue SCrypt::Errors::InvalidHash | |
nil | |
end | |
def value_coerced?(value) | |
value.instance_of?(SCrypt::Password) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment