]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Add generate_password equivalent script
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Sat, 17 Feb 2018 23:15:28 +0000 (00:15 +0100)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Sun, 18 Feb 2018 00:12:24 +0000 (01:12 +0100)
bin/generate_password [new file with mode: 0755]

diff --git a/bin/generate_password b/bin/generate_password
new file mode 100755 (executable)
index 0000000..9a2abb1
--- /dev/null
@@ -0,0 +1,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