Sha256: 6cbebe5b45efd2dc37ec232f0da3d353e3498eb58e2ae5de3246da1aeac8c411

Contents?: true

Size: 1.31 KB

Versions: 18

Compression:

Stored size: 1.31 KB

Contents

module Clearance
  module PasswordStrategies
    # Uses BCrypt to authenticate users and store encrypted passwords.
    #
    # BCrypt has a `cost` argument which determines how computationally
    # expensive the hash is to calculate. The higher the cost, the harder it is
    # for attackers to crack passwords even if they posess a database dump of
    # the encrypted passwords. Clearance uses the `bcrypt-ruby` default cost
    # except in the test environment, where it uses the minimum cost value for
    # speed. If you wish to increase the cost over the default, you can do so
    # by setting a higher cost in an initializer:
    # `BCrypt::Engine.cost = 12`
    module BCrypt
      require 'bcrypt'

      def authenticated?(password)
        if encrypted_password.present?
          ::BCrypt::Password.new(encrypted_password) == password
        end
      end

      def password=(new_password)
        @password = new_password

        if new_password.present?
          self.encrypted_password = ::BCrypt::Password.create(
            new_password,
            cost: configured_bcrypt_cost,
          )
        end
      end

      def configured_bcrypt_cost
        if defined?(::Rails) && ::Rails.env.test?
          ::BCrypt::Engine::MIN_COST
        else
          ::BCrypt::Engine.cost
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
clearance-2.9.3 lib/clearance/password_strategies/bcrypt.rb
clearance-2.9.2 lib/clearance/password_strategies/bcrypt.rb
clearance-2.9.1 lib/clearance/password_strategies/bcrypt.rb
clearance-2.9.0 lib/clearance/password_strategies/bcrypt.rb
clearance-2.8.0 lib/clearance/password_strategies/bcrypt.rb
clearance-2.7.2 lib/clearance/password_strategies/bcrypt.rb
clearance-2.7.0 lib/clearance/password_strategies/bcrypt.rb
clearance-2.6.2 lib/clearance/password_strategies/bcrypt.rb
clearance-2.6.1 lib/clearance/password_strategies/bcrypt.rb
clearance-2.6.0 lib/clearance/password_strategies/bcrypt.rb
clearance-2.5.0 lib/clearance/password_strategies/bcrypt.rb
clearance-2.4.0 lib/clearance/password_strategies/bcrypt.rb
clearance-2.3.1 lib/clearance/password_strategies/bcrypt.rb
clearance-2.3.0 lib/clearance/password_strategies/bcrypt.rb
clearance-2.2.1 lib/clearance/password_strategies/bcrypt.rb
clearance-2.2.0 lib/clearance/password_strategies/bcrypt.rb
clearance-2.1.0 lib/clearance/password_strategies/bcrypt.rb
clearance-2.0.0 lib/clearance/password_strategies/bcrypt.rb