Last active
September 3, 2022 00:22
-
-
Save v0lkan/4805adff88cbb61464da to your computer and use it in GitHub Desktop.
salted sha
This file contains hidden or 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
#!/usr/bin/env bash | |
# Warning: SHA1 is considered cryptographically broken. | |
# Do not use it for very sensitive stuff. | |
# It’s “good enough” for not-so-sensitive stuff. | |
die () { | |
echo >&2 "$@" | |
echo "Usage: ssha.sh username password" | |
exit 1 | |
} | |
[ "$#" -eq 2 ] || die "2 arguments required, $# provided." | |
USERNAME="$1" | |
PASSWORD="$2" | |
SALT="$(openssl rand -base64 3)" | |
SHA1=$(printf "$PASSWORD$SALT" | openssl dgst -binary -sha1 | sed 's#$#'"$SALT"'#' | base64) | |
printf "$USERNAME:{SSHA}$SHA1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment