diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-02-18 00:15:28 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-02-18 01:12:24 +0100 |
commit | 47d7d947ebc0da8bde02515a94d8205df47c944a (patch) | |
tree | 22ed4f129b32201e4f3e562d2f23cc45c5df5afb /bin/generate_password | |
parent | 7c43beaa3f3a6eab784f6cbca79955c9f6a7fff9 (diff) | |
download | Puppet-47d7d947ebc0da8bde02515a94d8205df47c944a.tar.gz Puppet-47d7d947ebc0da8bde02515a94d8205df47c944a.tar.zst Puppet-47d7d947ebc0da8bde02515a94d8205df47c944a.zip |
Add generate_password equivalent script
Diffstat (limited to 'bin/generate_password')
-rwxr-xr-x | bin/generate_password | 26 |
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 | |||
3 | require "openssl" | ||
4 | |||
5 | arguments = ARGV | ||
6 | |||
7 | if arguments.size != 3 | ||
8 | puts "generate_password <size> <seed_file> <password_key>" | ||
9 | exit | ||
10 | end | ||
11 | |||
12 | size = arguments.shift | ||
13 | seed_file = arguments.shift | ||
14 | password_key = arguments.shift | ||
15 | |||
16 | size = size.to_i | ||
17 | |||
18 | set = ('a' .. 'z').to_a + ('A' .. 'Z').to_a + ('0' .. '9').to_a | ||
19 | |||
20 | key = "#{File.open(seed_file).read}:#{password_key}" | ||
21 | |||
22 | password = size.times.collect do |i| | ||
23 | set[OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, i.to_s).to_i(16) % set.size] | ||
24 | end.join | ||
25 | |||
26 | puts password | ||