-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword_generator.rb
More file actions
21 lines (20 loc) · 1006 Bytes
/
password_generator.rb
File metadata and controls
21 lines (20 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module PasswordGenerator
def PasswordGenerator.generateRandomPass(number_of_chars)
allowed_chars = {
:lowercase => ('a'..'z').to_a,
:uppercase => ('A'..'Z').to_a,
:numbers => ('0'..'9').to_a,
:symbols => ['!', '"', '#', "\$", '%', '&', "\'", "\(", "\)", '*', '+', "\,", '-', "\.", '/', "\:",
"\;", '<', "\=", '>', '?', "\@", '[', "\\", "\]", '^', "\_", "\'", "\{", '|', "\}", "\~"]
}
num_of_lowercase = rand(1..number_of_chars - 3)
num_of_uppercase = rand(1..number_of_chars - num_of_lowercase - 2)
num_of_numbers = rand(1..number_of_chars - num_of_lowercase - num_of_uppercase - 1)
num_of_symbols = number_of_chars - num_of_lowercase - num_of_uppercase - num_of_numbers
pass = allowed_chars[:lowercase].shuffle()[0..num_of_lowercase - 1] +
allowed_chars[:uppercase].shuffle()[0..num_of_uppercase - 1] +
allowed_chars[:numbers].shuffle()[0..num_of_numbers - 1] +
allowed_chars[:symbols].shuffle()[0..num_of_symbols - 1]
pass = pass.shuffle.join
end
end