23 lines
739 B
Bash
23 lines
739 B
Bash
|
die() {
|
||
|
echo "$@" >&2
|
||
|
exit 1
|
||
|
}
|
||
|
|
||
|
magic='$z$'
|
||
|
redis_socket=$1
|
||
|
read -p "Username: " username
|
||
|
read -s -p "Password: " password
|
||
|
echo
|
||
|
read -s -p "Confirm your password: " password_conf
|
||
|
echo
|
||
|
if [[ $password != $password_conf ]]; then
|
||
|
die "Passwords don't match"
|
||
|
fi
|
||
|
|
||
|
salt=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13)
|
||
|
|
||
|
encoded_hash=$({ echo -n $magic; echo -n $password; echo -n $salt; } | sha512sum - \
|
||
|
| xxd -r -p | od -tx1 - | sed -e 's/^[0-9]* //' -e '$d' -e 's/^/ /' -e 's/ /\\x/g' | tr -d '\n')
|
||
|
redis-cli -s $redis_socket set salt:$username $salt || die "Failed to send redis command"
|
||
|
echo \'\"$encoded_hash\"\' | xargs -n 1 redis-cli --quoted-input -s $redis_socket set hash:$username || die "Failed to send redis command"
|