From aa14500a5d038cb207a846d63191854741abd919 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 29 Nov 2019 20:50:25 +0000 Subject: [PATCH] pash: generate password using /dev/urandom, dd and tr --- pash | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/pash b/pash index 1d79e37..ff63ea5 100755 --- a/pash +++ b/pash @@ -6,20 +6,8 @@ pw_add() { name=$1 if yn "Generate a password?"; then - # Use 'gpg' to generate the password. This could have - # been 'openssl', '/dev/[u]random' or another utility, - # however sticking to 'gpg' removes the need for another - # dependency. - # - # The '-a' flag outputs the random bytes as a 'base64' - # encoded string to allow for the password to be used as - # well, a password. - # - # The 'cut' is required to actually truncate the password - # to the set length as the 'base64' encoding makes the - # resulting string longer than the given length. - pass=$("$gpg" -a --gen-random 1 "${PASH_LENGTH:-50}" |\ - cut -c -"${PASH_LENGTH:-50}") + pass=$(tr -dc "${PASH_PATTERN:-_A-Z-a-z-0-9}" /dev/null) else printf 'Enter password: '