#!/usr/bin/ksh

PASSWORDS_REQUIRED=$1 export PASSWORDS_REQUIRED
CHAR_REQUIRED=$2 export CHAR_REQUIRED
case "$PASSWORDS_REQUIRED" in

	[a-z])	
		echo "\n\tnew_generator: invalid argument"
		echo "\tnew_generator: no_of_passwords no_of_characters"
		exit
			;;
	*)	if [ "`echo $PASSWORDS_REQUIRED | wc -w`" -gt 1 -o "`echo $CHAR_REQUIRED | wc -w`" -gt 1 ]
		then
			echo "\n\tnew_generator: invalid number of arguments"
			echo "new_generator: no_of_passwords no_of_characters"
			exit
		
		else
			continue
		fi

		if [ "$PASSWORDS_REQUIRED" = "" -o "$CHAR_REQUIRED" = "" ]
		then
			echo "\n\tnew_generator: invalid argument"
			echo "\tnew_generator: no_of_passwords no_of_characters"
			exit
		fi
			;;

			
esac

PASSWORDS_CREATED=0

until [ "$PASSWORDS_CREATED" = "$PASSWORDS_REQUIRED" ]
do
	COUNT=0
	ADD_STRING=
	STRING=6IpNqP1o9AwCiReOrQuZtF7y5JlMaLkGsW3dBjDf8VhXgSvYbT2zHxUmE4cnK0

until [ ${COUNT} = "$CHAR_REQUIRED" ]
do
		NUMCOUNT=`expr $RANDOM \* $RANDOM | cut -c1,2`

	if [ "$NUMCOUNT" -ge 62 ]
	then
		NUMCOUNT=`expr $NUMCOUNT \/ 2 | awk -F. '{print $1}'`
	fi
		ADD_STRING=${ADD_STRING}`echo $STRING | cut -c${NUMCOUNT}`

		COUNT=`expr $COUNT + 1` export COUNT
done

		echo $ADD_STRING 
		echo $ADD_STRING >>PASSWORD_FILE
		PASSWORDS_CREATED=`expr $PASSWORDS_CREATED + 1`
done

