MySQL password hash creator

#!/bin/sh

C_AWK="$(which awk)"
C_SHA1SUM="$(which sha1sum)"
C_TR="$(which tr)"
C_XXD="$(which xxd)"

echo -n "MySQL password: "

read PASSWORD

if [ ${#PASSWORD} -eq 0 ]; then
    echo "Invalid password length: 0"

    exit 1
fi

FIRST_HASH="$(echo -n "${PASSWORD}" | ${C_SHA1SUM} | ${C_AWK} '{print $1}')"
FIRST_HASH_BINARY="$(echo -n "${FIRST_HASH}" | ${C_XXD} -r -p)"
SECOND_HASH="$(echo -n "${FIRST_HASH_BINARY}" | ${C_SHA1SUM} | ${C_AWK} '{print $1}')"
SECOND_HASH_UPPER="$(echo -n "${SECOND_HASH}" | ${C_TR} [a-z] [A-Z])"

echo "*${SECOND_HASH_UPPER}"

exit 0

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.