Last active
January 15, 2017 20:19
-
-
Save handicraftsman/6fd6e9353d1524caad1c7a3536b57a83 to your computer and use it in GitHub Desktop.
Generates strong random passwords
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "date" | |
dt = DateTime.now | |
base = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a | |
blen = base.length | |
passlen = ARGV[0] | |
if passlen == "-" | |
passlen = gets | |
end | |
if passlen == nil then | |
fail "Passlen arg is not provided!" | |
end | |
if passlen[/\D+\n/] | |
fail "Given data is not number!" | |
end | |
passlen = passlen.to_i | |
pass = "" | |
tfa = %w[%Y %C %y %m %d %e %j %H %k %I %l %M %S %L %:::z %u %w %G %g %V %U %W %s %Q %3N %6N %9N %12N].shuffle | |
passlen.times do |i| | |
f = "" | |
tfa = tfa.shuffle | |
tfa.each do |o| | |
f << o | |
end | |
seed = | |
dt. | |
strftime(f). | |
delete(": "). | |
to_i | |
rndbts = Random.new.bytes(128).bytes.sum ** 4096 | |
s = Random.new_seed + seed + i*i + rndbts | |
s = s**128 | |
rnd = Random.new | |
pos = rnd.rand(0..(blen-1)) | |
pass << base[pos] | |
sleep 0.01 | |
end | |
(passlen.floor / 12).times do | |
pass[(0..(passlen-1)).to_a.sample] = "_" | |
pass[(0..(passlen-1)).to_a.sample] = "." | |
end | |
puts "#{pass}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment