Class: Zxcvbn::Matchers::Repeat

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

Instance Method Summary collapse

Instance Method Details

#matches(password) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/zxcvbn/matchers/repeat.rb', line 4

def matches(password)
  result = []
  i = 0
  while i < password.length
    j = i + 1
    loop do
      prev_char, cur_char = password[j-1..j]
      if password[j-1] == password[j]
        j += 1
      else
        if j - i > 2 # don't consider length 1 or 2 chains.
          result << Match.new(
            :pattern => 'repeat',
            :i => i,
            :j => j-1,
            :token => password[i...j],
            :repeated_char => password[i]
          )
        end
        break
      end
    end
    i = j
  end
  result
end