Rob Scripts

Rob writes bash scripts.

Random, memorable-ish password generator

June 12, 2015 — Rob Hutten

For when you need a new password or twelve. Not all /usr/dict/words files are created equally; I encourage finding/generating your own dictionary of short words.

#!/bin/bash
#
# Rob Hutten 2015
# http://hutten.org/rob/scripts/
# Generate some semi-not-horrible passwords
# Requires a 'sort' with the -R option.

function ranDigit() {
        echo $RANDOM | rev | cut -c1
}

function makeOne() {
        ( grep ^....$ $dict | sort -R | head -1 | sed "s/./\U&/"
          grep ^....$ $dict | sort -R | head -1
          ranDigit
          echo '; : . , = + -' | tr ' ' '\012' | sort -R | head -1
        ) | sort -R | tr -d '\012'
        echo
}

#-- main
PATH=/bin:/usr/bin
dict=/usr/share/dict/words

if [ $# -gt 0 ] ; then
        for i in $(seq 1 $1) ; do
                makeOne
        done
else
        makeOne
fi

Tags: passwords