Sha256: 65055f44a07a80e5c0d3415a08f44b966d9f72007f9c1e89e3f474340060b01f

Contents?: true

Size: 1.24 KB

Versions: 13

Compression:

Stored size: 1.24 KB

Contents

# frozen-string-literal: true

module Rodauth
  Feature.define(:disallow_common_passwords, :DisallowCommonPasswords) do
    depends :login_password_requirements_base

    auth_value_method :most_common_passwords_file, File.expand_path('../../../../dict/top-10_000-passwords.txt', __FILE__)
    translatable_method :password_is_one_of_the_most_common_message, "is one of the most common passwords"
    auth_value_method :most_common_passwords, nil

    auth_methods :password_one_of_most_common?

    def password_meets_requirements?(password)
      super && password_not_one_of_the_most_common?(password)
    end

    def post_configure
      super

      return if most_common_passwords || !most_common_passwords_file

      require 'set'
      most_common = Set.new(File.read(most_common_passwords_file).split("\n").each(&:freeze)).freeze
      self.class.send(:define_method, :most_common_passwords){most_common}
    end

    def password_one_of_most_common?(password)
      most_common_passwords.include?(password)
    end

    private

    def password_not_one_of_the_most_common?(password)
      return true unless password_one_of_most_common?(password)
      @password_requirement_message = password_is_one_of_the_most_common_message
      false
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rodauth-2.12.0 lib/rodauth/features/disallow_common_passwords.rb
rodauth-2.11.0 lib/rodauth/features/disallow_common_passwords.rb
rodauth-2.10.0 lib/rodauth/features/disallow_common_passwords.rb
rodauth-2.9.0 lib/rodauth/features/disallow_common_passwords.rb
rodauth-2.8.0 lib/rodauth/features/disallow_common_passwords.rb
rodauth-2.7.0 lib/rodauth/features/disallow_common_passwords.rb
rodauth-2.6.0 lib/rodauth/features/disallow_common_passwords.rb
rodauth-2.5.0 lib/rodauth/features/disallow_common_passwords.rb
rodauth-2.4.0 lib/rodauth/features/disallow_common_passwords.rb
rodauth-2.3.0 lib/rodauth/features/disallow_common_passwords.rb
rodauth-2.2.0 lib/rodauth/features/disallow_common_passwords.rb
rodauth-2.1.0 lib/rodauth/features/disallow_common_passwords.rb
rodauth-2.0.0 lib/rodauth/features/disallow_common_passwords.rb