#!/bin/sh

# This file is in the public domain

# Note: requires an echo that understands '-n', an expr that understands
# 'quote', and of course the md5sum command. In short, this is not very
# likely to work on non-GNUish systems. Too bad for now.

if [ "$1" = "" ]
then
	echo Usage: $0 cleartext [salt]
	exit 1
fi
CLEAR=$1

if [ "$2" != "" ]
then
	# Take first 4 chars of salt argument (padded on right if shorter)
	SALT=`expr substr ${2}ABCD 1 4`
else
	# Take last 4 chars of what 'tempfile' gives if none
	SALT=`tempfile` ; rm -f $SALT
	SALT=`expr substr \( quote ABCD${SALT} \) \( \( length \( quote ABCD${SALT} \) \) - 3 \) 4`
fi

echo "Md5-Hex-Password: ${SALT}\$"`echo -n ${CLEAR}${SALT} | md5sum`

