Created
June 8, 2017 18:53
-
-
Save sjmcgrath/ea15f1485aaaf9aa9220974ae40643ee to your computer and use it in GitHub Desktop.
Hash a role/password for a CREATE ROLE... in PostgreSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
[[ $# -eq 0 ]] || { | |
cat <<EOF >&2 | |
Usage: ${0##*/} | |
Prompts for Role and Password and outputs the hash in the correct format for a | |
"CREATE ROLE ... PASSWORD 'xxx';" in PostgreSQL. | |
EOF | |
exit 1 | |
} | |
read -p 'Role: ' ROLE | |
read -s -p 'Password: ' PASSWORD | |
PREFIX=md5 | |
HASH=$( echo -n "${PASSWORD}${ROLE}" | md5sum | cut -d ' ' -f 1 ) | |
echo ${PREFIX}${HASH} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment