aboutsummaryrefslogblamecommitdiff
path: root/bin/generate_password
blob: 9a2abb1b539291902768d45ddd0c518c413c717e (plain) (tree)

























                                                                                              
#!/bin/env ruby

require "openssl"

arguments = ARGV

if arguments.size != 3
  puts "generate_password <size> <seed_file> <password_key>"
  exit
end

size = arguments.shift
seed_file = arguments.shift
password_key = arguments.shift

size = size.to_i

set = ('a' .. 'z').to_a + ('A' .. 'Z').to_a + ('0' .. '9').to_a

key = "#{File.open(seed_file).read}:#{password_key}"

password = size.times.collect do |i|
  set[OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, i.to_s).to_i(16) % set.size]
end.join

puts password