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 |
# File 'lib/password_list_generator/generator.rb', line 10 def generate passwords = [] 1.upto(config.count) do valid = false random = '' until valid random_size = (config.min..config.max).to_a.shuffle.first random = (1..random_size).map {|a| characters_set[SecureRandom.random_number(characters_set.size)]}.join password = Password.new(random, config) if password.valid? passwords << password valid = true end end end passwords end |