Sha256: 22cd584a99575abda08941de08400738a21c48ee74d733ef3c46e982f0799a93

Contents?: true

Size: 786 Bytes

Versions: 3

Compression:

Stored size: 786 Bytes

Contents

module Clearance
  module PasswordStrategies
    module BCrypt
      require 'bcrypt'

      extend ActiveSupport::Concern

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

      def password=(new_password)
        @password = new_password

        if new_password.present?
          self.encrypted_password = encrypt(new_password)
        end
      end

      private

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

      def cost
        if test_environment?
          ::BCrypt::Engine::MIN_COST
        else
          ::BCrypt::Engine::DEFAULT_COST
        end
      end

      def test_environment?
        defined?(::Rails) && ::Rails.env.test?
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
clearance-1.4.0 lib/clearance/password_strategies/bcrypt.rb
clearance-1.3.0 lib/clearance/password_strategies/bcrypt.rb
clearance-1.2.1 lib/clearance/password_strategies/bcrypt.rb