-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash-password.sh
executable file
·55 lines (42 loc) · 1.11 KB
/
hash-password.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
DEFAULT_PASSWORD=${DEFAULT_PASSWORD:-dddlab}
IMAGE=${IMAGE:-ghcr.io/dddlab/jupyter-passwd}
TAG=${TAG:-latest}
IMAGE_TAG=${IMAGE_TAG:-${IMAGE}:${TAG}}
function password_input {
N_TRIES=1
while [[ $N_TRIES -le 3 ]]
do
# turn off echo for password input
stty -echo
printf "Enter a password: " >&2
read PASSWORD
printf "\nConfirm password: " >&2
read CONFPASS
stty echo
if [ "$PASSWORD" = "$CONFPASS" ]
then
printf "\n" >&2
return
else
printf "\nEntered passwords are not equal\n"
((N_TRIES++))
fi
done
PASSWORD="$DEFAULT_PASSWORD" # use default password
echo "Entered passwords are not equal"
echo "Using default password, '$DEFAULT_PASSWORD'"
}
if [[ -z ${PASSWORD} ]];
then
password_input
else
echo "Using PASSWORD variable: '$PASSWORD'"
echo "Container image: ${IMAGE_TAG}"
fi
HASHED=$(\
docker run --rm ${IMAGE_TAG} \
python -c \
"from notebook.auth import passwd; \
print(passwd('$PASSWORD', 'sha1'))")
echo $HASHED