Skip to content

Instantly share code, notes, and snippets.

@shinkbr
Created January 21, 2018 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinkbr/d257a004a98f562550a78abfc8ffb69a to your computer and use it in GitHub Desktop.
Save shinkbr/d257a004a98f562550a78abfc8ffb69a to your computer and use it in GitHub Desktop.
Generate random and complex passwords
#!/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