From a1eb0994fd065b4c1f628227fb606b15ab69084e Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Wed, 31 Aug 2022 16:59:58 +0300 Subject: [PATCH] dotfiles/zshrc: new genpass alias --- dotfiles/zshrc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/dotfiles/zshrc b/dotfiles/zshrc index 3dc3abb..ea4e02d 100644 --- a/dotfiles/zshrc +++ b/dotfiles/zshrc @@ -85,10 +85,18 @@ jpegoptimize() { gm mogrify -filter Triangle -define filter:support=2 -unsharp 2x0.5+0.7+0 -dither -quality $QUALITY -define jpeg:fancy-upsampling=off -interlace Line -strip -output-directory $2 $1 } -# generate random password 15 characters long -# See: https://unix.stackexchange.com/questions/230673/how-to-generate-a-random-string +# Generate a random hex password 20 characters long. The input from /dev/urandom +# does not need to be any particular length due to SHA-2 256's design (for exam- +# ple, the "avalanche" effect and the input padding), so I just read 1 byte with +# dd. Some sites (see below) recommend using a minimum of 20 characters for hex +# passwords. +# +# See: https://www.ssh.com/academy/ssh/passphrase-generator genpass() { - ?@[\]^_`{|}~' | head -c 15 ; echo + dd if=/dev/urandom bs=1 count=1 2>/dev/null | \ + sha256sum -b | \ + sed 's/ .*//' | \ + head -c 20; echo } # set GPG TTY for pinentry-curses