#!/bin/bash # # passphrase_simple [4words|hex|uuid|base64|cleaned] # # Very simple passphrase generator using various methods # # For a better more complex one look at "passphrase_generator" # # NOTE: This may not generate passphrases that satisfy the 'old rules' of # having lowercase, uppercase, digits, punctuation. Though it does more than # satisfy the typical minimum length requirements of such systems. # #### # Anthony Thyssen 29 Oct 2019 # # Generate a random password generate_password() { case "$1" in 4words) # four random words, XKCD style, with separator symbol # # Word source dictionary="$HOME/lib/dict/dict_diceware_eff" [ -f "$dictionary" ] || dictionary=/usr/share/dict/words # Seperation symbol sep=$( shuf -en1 -- - _ + = \# \* : \| \~ ^ . , / \\\\ @ ! \? % \$ \& ) # Create passphrase grep -E '^[[:alpha:]]{3,9}$' "$dictionary" | shuf -n4 | paste -d"$sep" -s ;; hex) # Deterministic password generation - always same for a specifc user # alternatives: shasum, sha224sum md5sum <<<"$user" | cut -f1 -d' ' ;; uuid) # 32 hexadecimal with 4 hyphens uuidgen ;; base64) # 24 random base64 characters openssl rand -base64 18 | cut -c1-24 ;; cleaned) # Substitute characters which could be misinterperted # EG: some character groups all look simular, EG: 0OQ # and some puncuation (like dot) may not print clearly openssl rand -base64 18 | cut -c1-24 | tr '0OQ1lI|!8B./+^#;' 'XYZabc67rst234uv' ;; *) echo >&2 "Usage: ${BASH_SOURCE##*/} [4words|hex|uuid|base64|cleaned]" exit 1 ;; esac } generate_password "${1:-4words}"