Class: Zxcvbn::Matchers::Dictionary Private

Inherits:
Object
  • Object
show all
Defined in:
lib/zxcvbn/matchers/dictionary.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.

Matches any sequential segment of the lowercased password that appears in a ranked dictionary.

Instance Method Summary collapse

Constructor Details

#initialize(name, ranked_dictionary, trie = nil) ⇒ Dictionary

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 Dictionary.

Parameters:

  • name (String)

    dictionary identifier used in match results

  • ranked_dictionary (Hash{String => Integer})

    lowercased word → rank

  • trie (Trie, nil) (defaults to: nil)

    optional prefix trie for faster lookups



14
15
16
17
18
# File 'lib/zxcvbn/matchers/dictionary.rb', line 14

def initialize(name, ranked_dictionary, trie = nil)
  @name = name
  @ranked_dictionary = ranked_dictionary
  @trie = trie
end

Instance Method Details

#matches(password) ⇒ 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 dictionary matches found in password.

Parameters:

  • password (String)

Returns:

  • (Array<MatchBuilder>)

    matches with pattern “dictionary”



24
25
26
27
28
29
30
31
32
# File 'lib/zxcvbn/matchers/dictionary.rb', line 24

def matches(password)
  lowercased_password = password.downcase

  if @trie
    trie_matches(password, lowercased_password)
  else
    hash_matches(password, lowercased_password)
  end
end