Skip to content

Instantly share code, notes, and snippets.

@lukebakken
Last active June 20, 2022 02:54
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e to your computer and use it in GitHub Desktop.
Save lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e to your computer and use it in GitHub Desktop.
RabbitMQ - Create Hashed User Password
#!/usr/bin/env bash
set -o errexit
set -o nounset
declare -r passwd="${1:-newpassword}"
declare -r tmp0="$(mktemp)"
declare -r tmp1="$(mktemp)"
function onexit
{
rm -f "$tmp0"
rm -f "$tmp1"
}
trap onexit EXIT
dd if=/dev/urandom of="$tmp0" count=4 bs=1 > /dev/null 2>&1
cp -f "$tmp0" "$tmp1"
echo -n "$passwd" >> "$tmp0"
openssl dgst -binary -sha256 "$tmp0" >> "$tmp1"
openssl base64 -A -in "$tmp1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment