7
8
9
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
38
39
40
41
42
43
44
|
# File 'lib/password_util/generator.rb', line 7
def generate
config.validate!
charset = []
password = []
if config.has_upper_letters
charset << config.upper_letters
config.min_upper_letters.times do
password << config.upper_letters.sample
end
end
if config.has_lower_letters
charset << config.lower_letters
config.min_lower_letters.times do
password << config.lower_letters.sample
end
end
if config.has_numbers
charset << config.numbers
config.min_numbers.times do
password << config.numbers.sample
end
end
if config.has_symbols
charset << config.symbols
config.min_symbols.times do
password << config.symbols.sample
end
end
password.shuffle!
password << charset.sample.sample while password.length < config.password_length
password.join('')[0...config.password_length]
end
|