Class: PasswordListGenerator::Generator
- Inherits:
-
Object
- Object
- PasswordListGenerator::Generator
- Defined in:
- lib/password_list_generator/generator.rb
Instance Attribute Summary collapse
-
#characters_set ⇒ Object
Returns the value of attribute characters_set.
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(config) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(config) ⇒ Generator
Returns a new instance of Generator.
5 6 7 8 |
# File 'lib/password_list_generator/generator.rb', line 5 def initialize(config) @config = config build_characters_set end |
Instance Attribute Details
#characters_set ⇒ Object
Returns the value of attribute characters_set.
3 4 5 |
# File 'lib/password_list_generator/generator.rb', line 3 def characters_set @characters_set end |
#config ⇒ Object
Returns the value of attribute config.
3 4 5 |
# File 'lib/password_list_generator/generator.rb', line 3 def config @config end |
Instance Method Details
#generate ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/password_list_generator/generator.rb', line 10 def generate passwords = [] tries = 0 catch :no_valid_passwords do 1.upto(config.count) do tries = 0 valid = false until valid random_size = (config.min..config.max).to_a.shuffle.first password = Password.new(random_string(random_size), config) if password.valid? passwords << password valid = true else tries += 1 throw :no_valid_passwords if tries > 10 end end end end raise "There was a problem creating valid passwords." if tries > 10 passwords end |