Class: Passwd::Policy
- Inherits:
-
Object
- Object
- Passwd::Policy
- 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
- #configure {|_self| ... } ⇒ Object
- #include_char?(letters, strings) ⇒ Boolean
-
#initialize ⇒ Policy
constructor
A new instance of Policy.
- #reset ⇒ Object
- #valid?(password, config) ⇒ Boolean
Constructor Details
#initialize ⇒ Policy
16 17 18 |
# File 'lib/passwd/configuration/policy.rb', line 16 def initialize reset end |
Instance Method Details
#configure {|_self| ... } ⇒ Object
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 |
#reset ⇒ Object
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 |