Class: Passwd::Policy

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/passwd/configuration/policy.rb

Constant Summary collapse

VALID_OPTIONS_KEYS =
[
  :min_length,
  :require_lower,
  :require_upper,
  :require_number
].freeze

Instance Method Summary collapse

Constructor Details

#initializePolicy



16
17
18
# File 'lib/passwd/configuration/policy.rb', line 16

def initialize
  reset
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



20
21
22
# File 'lib/passwd/configuration/policy.rb', line 20

def configure
  yield self
end

#include_char?(letters, strings) ⇒ Boolean



32
33
34
35
36
37
# File 'lib/passwd/configuration/policy.rb', line 32

def include_char?(letters, strings)
  strings.each_char do |c|
    return true if letters.include? c
  end
  false
end

#resetObject



39
40
41
42
43
44
# File 'lib/passwd/configuration/policy.rb', line 39

def reset
  self.min_length = 8
  self.require_lower = true
  self.require_upper = false
  self.require_number = true
end

#valid?(password, config) ⇒ Boolean



24
25
26
27
28
29
30
# File 'lib/passwd/configuration/policy.rb', line 24

def valid?(password, config)
  return false if self.min_length > password.size
  return false if self.require_lower && !include_char?(config.letters_lower, password)
  return false if self.require_upper && !include_char?(config.letters_upper, password)
  return false if self.require_number && !include_char?(config.letters_number, password)
  true
end