Class: Zxcvbn::Matchers::L33t Private
- Inherits:
-
Object
- Object
- Zxcvbn::Matchers::L33t
- Defined in:
- lib/zxcvbn/matchers/l33t.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 dictionary words after substituting common l33t-speak character replacements (e.g. “@” for “a”, “3” for “e”).
Constant Summary collapse
- L33T_TABLE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Mapping from plain letter to the l33t characters that can represent it.
{ 'a' => ['4', '@'].freeze, 'b' => ['8'].freeze, 'c' => ['(', '{', '[', '<'].freeze, 'e' => ['3'].freeze, 'g' => ['6', '9'].freeze, 'i' => ['1', '!', '|'].freeze, 'l' => ['1', '|', '7'].freeze, 'o' => ['0'].freeze, 's' => ['$', '5'].freeze, 't' => ['+', '7'].freeze, 'x' => ['%'].freeze, 'z' => ['2'].freeze }.freeze
Instance Method Summary collapse
-
#initialize(dictionary_matchers) ⇒ L33t
constructor
private
A new instance of L33t.
-
#l33t_subs(table) ⇒ Array<Hash{String => String}>
private
Enumerates all possible substitution combinations for the given l33t subtable.
-
#matches(password) ⇒ Array<MatchBuilder>
private
Returns l33t-substituted dictionary matches found in password.
-
#relevent_l33t_subtable(password) ⇒ Hash{String => Array<String>}
private
Returns the subset of L33T_TABLE whose l33t characters appear in password.
-
#translate(password, sub) ⇒ String
private
Returns a copy of password with each character replaced according to sub.
Constructor Details
#initialize(dictionary_matchers) ⇒ L33t
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 L33t.
26 27 28 |
# File 'lib/zxcvbn/matchers/l33t.rb', line 26 def initialize(dictionary_matchers) @dictionary_matchers = dictionary_matchers end |
Instance Method Details
#l33t_subs(table) ⇒ Array<Hash{String => String}>
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.
Enumerates all possible substitution combinations for the given l33t subtable.
80 81 82 83 84 85 |
# File 'lib/zxcvbn/matchers/l33t.rb', line 80 def l33t_subs(table) keys = table.keys subs = [[]] subs = find_substitutions(subs, table, keys) subs.map(&:to_h) end |
#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 l33t-substituted dictionary matches found in password.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/zxcvbn/matchers/l33t.rb', line 34 def matches(password) matches = [] lowercased_password = password.downcase relevent_subtable = relevent_l33t_subtable(lowercased_password) # Early bailout: if no l33t characters present, return empty matches return matches if relevent_subtable.empty? combinations_to_try = l33t_subs(relevent_subtable) combinations_to_try.each do |substitution| @dictionary_matchers.each do |matcher| subbed_password = translate(lowercased_password, substitution) matcher.matches(subbed_password).each do |match| process_match(match, password, substitution, matches) end end end matches end |
#relevent_l33t_subtable(password) ⇒ Hash{String => Array<String>}
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 the subset of L33T_TABLE whose l33t characters appear in password.
67 68 69 70 71 72 73 74 |
# File 'lib/zxcvbn/matchers/l33t.rb', line 67 def relevent_l33t_subtable(password) filtered = {} L33T_TABLE.each do |letter, subs| relevent_subs = subs.select { |s| password.include?(s) } filtered[letter] = relevent_subs unless relevent_subs.empty? end filtered end |
#translate(password, sub) ⇒ String
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 copy of password with each character replaced according to sub.
59 60 61 |
# File 'lib/zxcvbn/matchers/l33t.rb', line 59 def translate(password, sub) password.gsub(Regexp.union(sub.keys), sub) end |