Skip to content

Instantly share code, notes, and snippets.

@cam8001
Last active June 7, 2017 13:50
Show Gist options
  • Save cam8001/75daa3cec6e45428f8e6497c907365e9 to your computer and use it in GitHub Desktop.
Save cam8001/75daa3cec6e45428f8e6497c907365e9 to your computer and use it in GitHub Desktop.
Quick and dirty password generator for macOS
#!/bin/bash
# Generates readable, word based passwords with random numbers attached.
# Example pass: Foo73-bar22
# Passwords take 'centuries' to crack according to https://github.com/dropbox/zxcvbn
DICT_FILE='/usr/share/dict/words'
#DICT_FILE_LENGTH=`python -c "import sys;num_lines = sum(1 for line in open('/usr/share/dict/words'));print num_lines"`
DICT_FILE_LENGTH='235886'
RANDOM_NUM=`od -vAn -N4 -tu < /dev/urandom`
RANDOM_NUM2=`od -vAn -N4 -tu < /dev/urandom`
WORD_ONE_IDX=`echo "$RANDOM_NUM % $DICT_FILE_LENGTH" | bc`
WORD_TWO_IDX=`echo "$RANDOM_NUM2 % $DICT_FILE_LENGTH" | bc`
WORD_ONE=`sed -n ''"$WORD_ONE_IDX"'p' < $DICT_FILE`
WORD_TWO=`sed -n ''"$WORD_TWO_IDX"'p' < $DICT_FILE`
NUM_ONE=`echo $((1 + RANDOM % 99))`
NUM_TWO=`echo $((1 + RANDOM % 99))`
# Uppercase the first letter.
WORD_ONE=`echo $WORD_ONE | perl -ne 'print ucfirst'`
echo "$WORD_ONE$NUM_ONE-$WORD_TWO$NUM_TWO" | tee /dev/tty | pbcopy
echo "Copied above password to clipboard."
@cam8001
Copy link
Author

cam8001 commented Jun 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment