Sha256: 428305327778eb080fd2b7c977f8860c57c2a2b8726f59417272268f2e60010b

Contents?: true

Size: 751 Bytes

Versions: 7

Compression:

Stored size: 751 Bytes

Contents

# frozen_string_literal: true

# Use argon instead of bcrypt for devise
# => https://ankane.org/devise-argon2
if defined?(Devise)
  module Argon2Encryptor
    def digest(klass, password)
      if klass.pepper.present?
        password = "#{password}#{klass.pepper}"
      end
      ::Argon2::Password.create(password)
    end

    def compare(klass, hashed_password, password)
      return false if hashed_password.blank?

      if hashed_password.start_with?('$argon2')
        if klass.pepper.present?
          password = "#{password}#{klass.pepper}"
        end
        ::Argon2::Password.verify_password(password, hashed_password)
      else
        super
      end
    end
  end

  Devise::Encryptor.singleton_class.prepend(Argon2Encryptor)
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kowl-0.0.7 lib/kowl/templates/config/initializers/devise_argon2.rb
kowl-0.0.6 lib/kowl/templates/config/initializers/devise_argon2.rb
kowl-0.0.5 lib/kowl/templates/config/initializers/devise_argon2.rb
kowl-0.0.4 lib/kowl/templates/config/initializers/devise_argon2.rb
kowl-0.0.3 lib/kowl/templates/config/initializers/devise_argon2.rb
kowl-0.0.2 lib/kowl/templates/config/initializers/devise_argon2.rb
kowl-0.0.1 lib/kowl/templates/config/initializers/devise_argon2.rb