aboutsummaryrefslogtreecommitdiff
path: root/bin/generate_password
diff options
context:
space:
mode:
Diffstat (limited to 'bin/generate_password')
-rwxr-xr-xbin/generate_password26
1 files changed, 26 insertions, 0 deletions
diff --git a/bin/generate_password b/bin/generate_password
new file mode 100755
index 0000000..9a2abb1
--- /dev/null
+++ b/bin/generate_password
@@ -0,0 +1,26 @@
1#!/bin/env ruby
2
3require "openssl"
4
5arguments = ARGV
6
7if arguments.size != 3
8 puts "generate_password <size> <seed_file> <password_key>"
9 exit
10end
11
12size = arguments.shift
13seed_file = arguments.shift
14password_key = arguments.shift
15
16size = size.to_i
17
18set = ('a' .. 'z').to_a + ('A' .. 'Z').to_a + ('0' .. '9').to_a
19
20key = "#{File.open(seed_file).read}:#{password_key}"
21
22password = size.times.collect do |i|
23 set[OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, i.to_s).to_i(16) % set.size]
24end.join
25
26puts password