Hey, thanks for the great improvements! I admit, my shell-fu is sub-par - I was mainly looking for a way to generate random strings from the shell, not necessarily in shell script. I went ahead and added the ruby
tag to reduce confusion.
That seems pretty handy! However, you might want to be careful using MD5 to generate passwords. The first hash was broken by this website in about three seconds (probably because the input password was so weak). Something stronger might be better, like PBKDF2 or bcrypt.
Since you're appending the current timestamp to your password, I assume you just want to generate any old password. If that's the case, you can read pseudo-random data straight out of /dev/urandom. Pass that through something like Ascii85 to convert to printable-characters only.
With Ruby and the Ascii85
gem installed:
cat /dev/urandom | ruby -rubygems -rascii85 -e "puts Ascii85.encode(STDIN.read(12))[2...-2]"
Closure::bind seems pretty similar to Ruby's
instance_eval
, or JavaScript'sFunction#bind
. Good to know that PHP has something like that!