#!/bin/sh

# Exit on the first command fail
set -e

# Defines expected results
EXPECTED=$(cat <<'EOF'
user_sunmd5:Debian
EOF
)

# Defines hashes to crack
HASHES=$(cat <<'EOF'
user_sunmd5:$md5$rounds=2$AABBCCDD$6HXyDGrhiaPHoQAZLmgrF/
EOF
)

# Temporary hash file to use
TMP="tmp_hashes"
echo "$HASHES" > ${TMP}

# Performs hash cracking by reading the wordlist from stdin
echo "debian Debian" | xargs -n1 | john --stdin --format=SunMD5 ${TMP}

# Retrieves results
ACTUAL=$(john --show $TMP)

echo "${EXPECTED}" |
    while read line
    do
	echo "${ACTUAL}" | grep -q ${line} 
    done

# Clean up, even if not needed in testbed
rm ${TMP}

# Exit success
exit 0
