-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword_generator.rb
65 lines (51 loc) · 1.12 KB
/
password_generator.rb
1
2
3
4
5
6
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module PasswordGenerator
@@word_patterns = ["vccvc", "cvcvcc", "cvccvc", "cvcvc"]
@@password_patterns = ["wnnc", "wnnn"]
def add_word_pattern pattern
@@word_patterns << pattern
end
def add_password_pattern pattern
@@password_patterns << pattern
end
def word_patterns
@@word_patterns
end
def password_patterns
@@password_patterns
end
def password_patterns= (patterns)
@@password_patterns = patterns
end
def word_patterns= (patterns )
@@word_patterns = patterns
end
def generate_password
read_pattern @@password_patterns.rand
end
def generate_word
read_pattern @@word_patterns.rand
end
protected
def vocal
['a', 'e', 'i', 'o', 'u', 'y'].rand
end
def consonant
['b', 'c', 'd', 'f','g','h','j','k','l','m','n','p','q','r','s','t','v','z'].rand
end
def read_pattern pattern
result = ""
pattern.each_byte do |a|
case a.chr
when 'v'
result += vocal
when 'c'
result += consonant
when 'w'
result += generate_word
when 'n'
result += rand(9).to_s
end
end
return result
end
end