Password Generator

This is a quick script to generate random 8-character passwords based on fragments of the UNIX spell-check dictionary, joined together with a random digit and punctuation symbol. Under Solaris 8, the file /usr/dict/words is the source for all these word fragments. For other versions of UNIX, you may have to change the "src=" line to point to your spell-check dictionary.

The script creates three temp files in /tmp and deletes them in the clean up phase.

This script has been recently updated to use the pwmangle password mangling script. You should change the value of the MANGLE script variable to the location of your version of pwmangle.


#!/bin/ksh

src=/usr/dict/words
MANGLE=/home/colinbr/bin/pwmangle

word1_tempfile=/tmp/words1$$
word2_tempfile=/tmp/words2$$
word3_tempfile=/tmp/words3$$

# Set the first word
echo "Generating first word list ..."
den1=`expr $RANDOM / 79`
first=`nl $src | grep $den1 |awk '{print $2}'`

# Set the second word
echo "Generating second word list ..."
den2=`expr $RANDOM / 37`
second=`nl $src | grep $den2 |awk '{print $2}'`

# Set the third word
echo "Generating third word list ..."
den3=`expr $RANDOM / 101`
third=`nl $src | grep $den3 |awk '{print $2}'`

echo "Generating first word component ..."
for word1 in $first 
do
    echo $word1 | awk '{
                          a = $1 ; b = length(a)
                          if (b <=4)
                              {
                                b1=a
                              }
                          else
                              {
                                b1=substr(a,2,4)
                              }
                                printf "%s \n", b1
                         }
                        ' >> $word1_tempfile
done

echo "Generating second word component ..."
for word2 in $second
do
    echo $word2 | awk '{
                         v = $1 ; u = length(v)
                         if (u <= 4 )
                             {
                               b2=v
                             }
                         else
                             {
                               b2=substr(v,2,4)
                             }
                               printf "%s \n", b2
                        }
                       ' >> $word2_tempfile
done

echo "Generating third word component ..."
for word3 in $third
do
    echo $word3 | awk '{
                         v = $1 ; u = length(v)
                         if (u <= 4 )
                             {
                               b2=v
                             }
                         else
                             {
                               b2=substr(v,2,4)
                             }
                               printf "%s \n", b2
                        }
                       ' >> $word3_tempfile
done

set -A x `head -50 $word1_tempfile | uniq` 
set -A y `tail -50 $word2_tempfile | uniq` 
set -A z `tail -50 $word3_tempfile | uniq` 

echo "Some Password Suggestions:"

for pw in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
do
   n=$((RANDOM%15+1))
   n1=$((RANDOM%15+1))
   printf "   $pw.   " 
   sugg=`echo ${x[$pw]} ${y[$pw]} ${z[$pw]} | sed -e 's/ //g'`
   printf "$sugg ... "
   chopped=`echo $sugg | cut -c3-10`
   printf "$chopped"
   mang=`$MANGLE -p $chopped`
   printf " ... $mang \n"
done

if [ -f $word1_tempfile ]; then
   rm $word1_tempfile
fi

if [ -f $word2_tempfile ]; then
   rm $word2_tempfile
fi

if [ -f $word3_tempfile ]; then
   rm $word3_tempfile
fi