lib/zxcvbn/matching.rb in zxcvbn-0.1.0 vs lib/zxcvbn/matching.rb in zxcvbn-0.1.1
- old
+ new
@@ -21,25 +21,26 @@
keypad: ADJACENCY_GRAPHS[:keypad],
mac_keypad: ADJACENCY_GRAPHS[:mac_keypad]
}
L33T_TABLE = {
- a: ['4', '@'],
- b: ['8'],
- c: ['(', '{', '[', '<'],
- e: ['3'],
- g: ['6', '9'],
- i: ['1', '!', '|'],
- l: ['1', '|', '7'],
- o: ['0'],
- s: ['$', '5'],
- t: ['+', '7'],
- x: ['%'],
- z: ['2']
+ "a" => ['4', '@'],
+ "b" => ['8'],
+ "c" => ['(', '{', '[', '<'],
+ "e" => ['3'],
+ "g" => ['6', '9'],
+ "i" => ['1', '!', '|'],
+ "l" => ['1', '|', '7'],
+ "o" => ['0'],
+ "s" => ['$', '5'],
+ "t" => ['+', '7'],
+ "x" => ['%'],
+ "z" => ['2']
}
REGEXEN = {
+ # alpha_lower: /[a-z]/,
# recent_year: /19\d\d|200\d|201\d/g
recent_year: /19\d\d|200\d|201\d/
}
DATE_MAX_YEAR = 2050
@@ -113,24 +114,14 @@
def self.empty(obj)
obj.empty?
end
- # extend: function(lst, lst2) {
- # return lst.push.apply(lst, lst2);
- # },
-
def self.translate(string, chr_map)
string.split('').map {|chr| chr_map[chr] || chr}.join("")
end
- def self.mod(n, m)
- # double check the need for this function
- binding.pry
- # return ((n % m) + m) % m; # mod impl that works for negative numbers
- end
-
def self.sorted(matches)
# sort on i primary, j secondary
matches.sort_by{|match| [match[:i], match[:j]] }
end
@@ -162,11 +153,11 @@
rank = ranked_dict[word]
matches << {
pattern: 'dictionary',
i: i,
j: j,
- token: password_lower[i..j],
+ token: password[i..j],
matched_word: word,
rank: rank,
dictionary_name: dictionary_name.to_s,
reversed: false,
l33t: false
@@ -335,11 +326,11 @@
matches = []
(0...password.length).each do |i|
j = i + 1
last_direction = nil
turns = 0
- if (graph_name == 'qwerty' || graph_name == 'dvorak') && SHIFTED_RX.match?(password[i])
+ if (graph_name == :qwerty || graph_name == :dvorak) && SHIFTED_RX.match?(password[i])
# initial character is shifted
shifted_count = 1
else
shifted_count = 0
end
@@ -383,11 +374,11 @@
matches << {
pattern: 'spatial',
i: i,
j: j - 1,
token: password[i..j],
- graph: graph_name,
+ graph: graph_name.to_s,
turns: turns,
shifted_count: shifted_count
}
end
# ...and then start a new search for the rest of the password.
@@ -471,10 +462,11 @@
return []
end
result = []
update = -> (i, j, delta) do
+ delta ||= 0
if j - i > 1 || (delta).abs == 1
if 0 < delta.abs && delta.abs <= MAX_DELTA
token = password[i..j]
if /^[a-z]+$/.match?(token)
sequence_name = 'lower'
@@ -537,11 +529,11 @@
matches << {
pattern: 'regex',
token: token,
i: rx_match.begin(0),
j: rx_match.end(0) - 1,
- regex_name: name,
+ regex_name: name.to_s,
regex_match: rx_match
}
match_index = rx_match.begin(0) + 1
end
end
@@ -570,20 +562,22 @@
# note: instead of using a lazy or greedy regex to find many dates over the full string,
# this uses a ^...$ regex against every substring of the password -- less performant but leads
# to every possible date match.
matches = []
maybe_date_no_separator = /^\d{4,8}$/
- maybe_date_with_separator = %r{
- ^
- ( \d{1,4} ) # day, month, year
- ( [\s/\\_.-] ) # separator
- ( \d{1,2} ) # day, month
- \2 # same separator
- ( \d{1,4} ) # day, month, year
- $
- }
+ # maybe_date_with_separator = %r{
+ # ^
+ # ( \d{1,4} ) # day, month, year
+ # ( [\s/\\_.-] ) # separator
+ # ( \d{1,2} ) # day, month
+ # \2 # same separator
+ # ( \d{1,4} ) # day, month, year
+ # $
+ # }
+ maybe_date_with_separator = /^(\d{1,4})([\s\/\\_.-])(\d{1,2})\2(\d{1,4})$/
+
(0..(password.length - 4)).each do |i|
(i + 3..i + 7).each do |j|
if j >= password.length
break
end
@@ -640,13 +634,13 @@
pattern: 'date',
token: token,
i: i,
j: j,
separator: rx_match[2],
- year: dmy.year,
- month: dmy.month,
- day: dmy.day
+ year: dmy[:year],
+ month: dmy[:month],
+ day: dmy[:day]
}
end
end
# matches now contains all valid date strings in a way that is tricky to capture
# with regexes only. while thorough, it will contain some unintuitive noise:
@@ -703,11 +697,11 @@
if DATE_MIN_YEAR <= y && y <= DATE_MAX_YEAR
dm = map_ints_to_dm(rest)
if dm
return {
year: y,
- month: dm.month,
- day: dm.day
+ month: dm[:month],
+ day: dm[:day]
}
else
# for a candidate that includes a four-digit year,
# when the remaining ints don't match to a day and month,
# it is not a date.