Created
January 21, 2018 20:19
-
-
Save shinkbr/d257a004a98f562550a78abfc8ffb69a to your computer and use it in GitHub Desktop.
Generate random and complex passwords
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# coding: utf-8 | |
length = 12 | |
if ARGV.size > 0 && (ARGV[0].to_i.to_s == ARGV[0]) && | |
ARGV[0].to_i >= 4 && ARGV[0].to_i <= 128 | |
length = ARGV[0].to_i | |
end | |
special = ' !"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'.split('') | |
alpha_lower = ('a'..'z').to_a | |
alpha_upper = ('A'..'Z').to_a | |
num = ('0'..'9').to_a | |
all = special + alpha_upper + alpha_lower + num | |
a = [special, alpha_upper, alpha_lower, num].map {|i| i.sample} | |
b = (length - a.length).times.collect { all.sample } | |
password = (a + b).shuffle.join('') | |
print password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment