Class: Zxcvbn::Omnimatch Private

Inherits:
Object
  • Object
show all
Defined in:
lib/zxcvbn/omnimatch.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Runs all registered matchers against a password and aggregates results.

Includes dictionary, l33t, spatial, digit, repeat, sequence, year, date, and reverse-dictionary matchers. User-supplied word lists are wrapped in transient matchers for each call to #matches.

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Omnimatch

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Omnimatch.

Parameters:

  • data (Data)

    loaded frequency lists and adjacency graphs



23
24
25
26
27
28
29
30
# File 'lib/zxcvbn/omnimatch.rb', line 23

def initialize(data)
  @data = data
  dicts = data.dictionaries
  @dictionary_matchers = dicts.ranked.map do |name, dictionary|
    Matchers::Dictionary.new(name, dictionary, dicts.tries[name]).freeze
  end.freeze
  @matchers = build_matchers.each(&:freeze).freeze
end

Instance Method Details

#matches(password, user_inputs = [], reference_year: Time.now.year) ⇒ Array<MatchBuilder>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns all matches found in the password across every registered matcher.

Parameters:

  • password (String)

    the password to analyse

  • user_inputs (Array<String>) (defaults to: [])

    caller-supplied words to add as a dictionary

  • reference_year (Integer) (defaults to: Time.now.year)

    year used by the date matcher to pick the closest candidate; shared with the scorer so both phases agree even across midnight

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/zxcvbn/omnimatch.rb', line 39

def matches(password, user_inputs = [], reference_year: Time.now.year)
  user_dictionary =
    user_inputs.any? && Matchers::Dictionary.new('user_inputs', DictionaryRanker.rank_dictionary(user_inputs))
  matchers = @matchers + user_input_matchers(user_dictionary)
  all_matches = matchers.flat_map do |matcher|
    case matcher
    when Matchers::Date
      matcher.matches(password, reference_year:)
    else
      matcher.matches(password)
    end
  end
  all_matches + reverse_dictionary_matches(password, user_dictionary)
end