Skip to content

Instantly share code, notes, and snippets.

@bagilevi
Created December 19, 2017 16:14
Show Gist options
  • Select an option

  • Save bagilevi/4523cc4a9cf057ffb2c8e02a73aacf52 to your computer and use it in GitHub Desktop.

Select an option

Save bagilevi/4523cc4a9cf057ffb2c8e02a73aacf52 to your computer and use it in GitHub Desktop.
password generator
#!/usr/bin/env ruby
lens = Array(ARGV[0]&.to_i || [20, 16, 10, 8, 6])
lo = 'qwertuiopasdfghjkxcvbnm'.split('')
up = 'QWERTUPASDFGHJKLXCVBNM'.split('')
nu = '123456789'.split('')
si = '!@#$%^&*()-=+[]{};\'\\:"|,./<>?'.split('')
lens.each do |len|
puts [
([ si.sample, nu.sample, up.sample, up.sample ] + (len - 4).times.map { lo.sample }).shuffle.join,
([ nu.sample, nu.sample, up.sample, up.sample ] + (len - 4).times.map { lo.sample }).shuffle.join,
len.times.map { lo.sample }.shuffle.join
].join(' ')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment