Skip to content

Instantly share code, notes, and snippets.

@sjmcgrath
Created June 8, 2017 18:53
Show Gist options
  • Save sjmcgrath/ea15f1485aaaf9aa9220974ae40643ee to your computer and use it in GitHub Desktop.
Save sjmcgrath/ea15f1485aaaf9aa9220974ae40643ee to your computer and use it in GitHub Desktop.
Hash a role/password for a CREATE ROLE... in PostgreSQL
#!/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