Generate easy passwords

This script generates combinations of words to form a password. These passwords are easier to remember than true random garbage combinations, which can’t be remembered by anyone. Moreover the passwords are not dictionary words and too difficult to be guessed by a brute force attack.

#!/bin/sh
# Author:       kdguntu@gmail.com
# Copyright:    (c) 2012 GNU Copyright v3
# Function:     Generate a password 
# Requires:     dictionary with words (here with dutch words from package hunspell)
#               perl
 
DICT="/usr/share/hunspell/nl_BE.dic"
NUMBEROFWORDS=4
MINWORDLENGTH=5
FIXWORDLENGTH=true # set to false to disable
 
####################
MINWLMIN1=`expr $MINWORDLENGTH - 1 `
TELLER=0
PASS=""
while [ $TELLER -lt $NUMBEROFWORDS ]             # 4 random words
do 
 RAND=`perl -e "print int rand(99999)"`
 WORD=`sed $RAND"q;d" $DICT | cut -d"/" -f1` 
 WORD=`echo ${WORD} | tr -cd '[[:lower:]]'`      # replace special chars with (a-z)
 CHARS=`echo $WORD|wc -c`
 if [ ${#WORD} -ge $MINWORDLENGTH ]; then        # wordlength at least 5
   if $FIXWORDLENGTH 
    then
       WORD=${WORD:0:$MINWORDLENGTH}             # cut at 5th char
       C5=`echo ${WORD:$MINWLMIN:1} | tr -cd 'aeiou'|wc -c`  
         if [ ${C5} -gt 0 ]                      # 5th char is vowel
            then  
              TELLER=`expr $TELLER + 1`
              PASS="$PASS${WORD^}"
         fi
    else
       TELLER=`expr $TELLER + 1`
       PASS="$PASS${WORD^}"
 
   fi
 fi
done
echo $PASS

I check if the 5th character is a vowel, because the combined password sounds (remembers) better that way. You can easily adapt the script with extra (or less) restrictions.
An example of the password it generates is “GemoePolieVergeTenni”

This entry was posted in bash, linux, macosx, regex, ubuntu and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *