aboutsummaryrefslogtreecommitdiff
path: root/bin/generate_password
blob: 9a2abb1b539291902768d45ddd0c518c413c717e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/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