Skip to content

Instantly share code, notes, and snippets.

@cam8001 cam8001/passwd_gen.sh
Last active Jun 7, 2017

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Jun 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.