Sha256: cee217580fee71c0833bad03ffdb4defb5b5503f82acc6c042587bd21fb6e488

Contents?: true

Size: 756 Bytes

Versions: 10

Compression:

Stored size: 756 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
          msg = "bcrypt cost cannot be set below the engine's min cost (#{::BCrypt::Engine::MIN_COST})"
          raise ArgumentError.new(msg), msg
        end
        @cost = val
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
authenticate-0.7.3 lib/authenticate/crypto/bcrypt.rb
authenticate-0.7.2 lib/authenticate/crypto/bcrypt.rb
authenticate-0.7.1 lib/authenticate/crypto/bcrypt.rb
authenticate-0.7.0 lib/authenticate/crypto/bcrypt.rb
authenticate-0.6.1 lib/authenticate/crypto/bcrypt.rb
authenticate-0.6.0 lib/authenticate/crypto/bcrypt.rb
authenticate-0.5.0 lib/authenticate/crypto/bcrypt.rb
authenticate-0.4.0 lib/authenticate/crypto/bcrypt.rb
authenticate-0.3.3 lib/authenticate/crypto/bcrypt.rb
authenticate-0.3.2 lib/authenticate/crypto/bcrypt.rb