Module: Philiprehberger::Password::Patterns

Defined in:
lib/philiprehberger/password/patterns.rb

Constant Summary collapse

QWERTY_ROWS =
%w[
  qwertyuiop
  asdfghjkl
  zxcvbnm
  1234567890
].freeze
QWERTY_ROWS_SHIFTED =
%w[
  !@#$%^&*()
].freeze
ALPHABETIC =
('a'..'z').to_a.join.freeze
NUMERIC =
('0'..'9').to_a.join.freeze
MIN_SEQUENCE_LENGTH =
3
MIN_REPEAT_LENGTH =
3

Class Method Summary collapse

Class Method Details

.detect(password) ⇒ Object

Detect keyboard patterns, sequences, and repeated characters in a password. Returns an array of hashes describing each detected pattern.



25
26
27
28
29
30
31
32
33
34
# File 'lib/philiprehberger/password/patterns.rb', line 25

def self.detect(password)
  pwd = password.to_s
  return [] if pwd.empty?

  patterns = []
  patterns.concat(detect_keyboard_rows(pwd))
  patterns.concat(detect_sequences(pwd))
  patterns.concat(detect_repeated_chars(pwd))
  patterns
end