Sha256: 7ad6a7a48d38525c0f138a04388779f8dc159db237e70d4c8d0f410fe1168864

Contents?: true

Size: 763 Bytes

Versions: 5

Compression:

Stored size: 763 Bytes

Contents

require 'rubygems'

gem 'bcrypt-ruby', '~>2.0.3'
require 'bcrypt'

module DataMapper
  module Types
    class BCryptHash < DataMapper::Type
      primitive String
      size 60

      def self.load(value, property)
        typecast(value, property)
      end

      def self.dump(value, property)
        typecast(value, property)
      end

      def self.typecast(value, property)
        if value.nil?
          nil
        else
          begin
            value.is_a?(BCrypt::Password) ? value : BCrypt::Password.new(value)
          rescue BCrypt::Errors::InvalidHash
            BCrypt::Password.create(value, :cost => BCrypt::Engine::DEFAULT_COST)
          end
        end
      end
    end # class BCryptHash
  end # module Types
end # module DataMapper

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
dm-types-0.9.10 lib/dm-types/bcrypt_hash.rb
dm-types-0.9.9 lib/dm-types/bcrypt_hash.rb
dm-types-0.9.8 lib/dm-types/bcrypt_hash.rb
mack-data_mapper-0.8.3 lib/gems/dm-types-0.9.9/lib/dm-types/bcrypt_hash.rb
mack-data_mapper-0.8.3.1 lib/gems/dm-types-0.9.9/lib/dm-types/bcrypt_hash.rb