Sha256: 98cea0de40295ccc5f69a1124e8850dbfb5cf08a6a67b834b1c8d84d6e410890

Contents?: true

Size: 727 Bytes

Versions: 7

Compression:

Stored size: 727 Bytes

Contents

module Authenticate
  module Crypto

    # All crypto providers must implement encrypt(secret) and match?(secret, encrypted)
    module BCrypt
      require 'bcrypt'

      def encrypt(secret)
        ::BCrypt::Password.create secret, cost: cost
      end

      def match?(secret, encrypted)
        return false unless encrypted.present?
        ::BCrypt::Password.new(encrypted) == secret
      end

      def cost
        @cost ||= ::BCrypt::Engine::DEFAULT_COST
      end

      def cost=(val)
        if val < ::BCrypt::Engine::MIN_COST
          raise ArgumentError.new("bcrypt cost cannot be set below the engine's min cost (#{::BCrypt::Engine::MIN_COST})")
        end
        @cost = val
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
authenticate-0.3.1 lib/authenticate/crypto/bcrypt.rb
authenticate-0.3.0 lib/authenticate/crypto/bcrypt.rb
authenticate-0.2.3 lib/authenticate/crypto/bcrypt.rb
authenticate-0.2.2 lib/authenticate/crypto/bcrypt.rb
authenticate-0.2.1 lib/authenticate/crypto/bcrypt.rb
authenticate-0.2.0 lib/authenticate/crypto/bcrypt.rb
authenticate-0.1.0 lib/authenticate/crypto/bcrypt.rb