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
45
|
# File 'lib/leetpassword.rb', line 9
def self.generate(max_len=nil, subs={i: '1', o: '0', e: '3'})
if max_len and max_len <= 6 then
raise "max length must be greater than 6 characters"
end
noun = RandomWord.nouns.next.gsub(/_/,'')
if max_len then
until noun.length >= 6 and noun.length <= max_len
noun = RandomWord.nouns.next.gsub(/_/,'')
end
end
subs.each{|k,v| noun.gsub!(k.to_s,v)}
return noun if noun.length > 7
adj = RandomWord.adjs.next.gsub(/_/,'')
if max_len then
until adj.length >= 6 and adj.length <= max_len
adj = RandomWord.adjs.next.gsub(/_/,'')
end
end
subs.each{|k,v| adj.gsub!(k.to_s,v)}
return adj if adj.length > 7
if max_len then
if (adj+noun).length <= max_len then
return adj + noun
else
LeetPassword.generate(max_len,subs)
end
else
return adj + noun
end
end
|