Skip to content

Instantly share code, notes, and snippets.

@trkoch
Created January 17, 2013 01:13
Show Gist options
  • Save trkoch/4552640 to your computer and use it in GitHub Desktop.
Save trkoch/4552640 to your computer and use it in GitHub Desktop.
#!/bin/bash
# hashapass.com based method for generating passwords
#
# Based on script by Simon Elmir
#
if ! args=$(getopt -o s -l silent -- "$@")
then
exit 1
fi
while [ $# -gt 0 ]
do
case $1 in
-s|--silent) silent="yes" ;;
-c|--copy) copy="yes" ;;
-l|--length) lengtharg="$2" ; shift ;;
(*) break;;
esac
shift
done
# Preserve whitespace
export IFS=""
# Length
length=${lengtharg:-"8"}
# Status
echo "Generating HMAC-SHA-1 with $length characters"
if [ $silent ]; then
echo "- Not echo hash to terminal"
fi
if [ $copy ]; then
echo "- Copy hash to system clipboard"
fi
read -rp "Parameter: " parameter
read -rsp "Master: " password
echo
hash=`echo -n "$parameter" \
| openssl dgst -sha1 -binary -hmac "$password" \
| openssl enc -base64 \
| cut -c 1-"$length"`
if ! [ $silent ]; then
echo $hash
fi
if [ $copy ]; then
echo -n $hash | pbcopy
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment