-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtransmission-pwgen.sh
32 lines (26 loc) · 1.04 KB
/
transmission-pwgen.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
#!/bin/bash
#
# https://github.com/tomwijnroks/transmission-pwgen
if [ -z $1 ]; then
# Define the password length.
PASSWORD_LENGTH=16
# Generate a random password (alphanumeric).
PASS=$(cat /dev/urandom | tr -dc '[:alnum:]' | fold -w ${PASSWORD_LENGTH} | head -n1)
else
PASS=$1
fi
# Generate a random salt (alphanumeric + two special characters).
# Source: https://github.com/transmission/transmission/blob/master/libtransmission/crypto-utils.c#L132-L136
SALT=$(cat /dev/urandom | tr -dc '[:alnum:]./' | fold -w 8 | head -n1)
# Combine password + salt and use sha1sum to create the hash.
HASH=$(echo -n ${PASS}${SALT} | sha1sum | awk '{print $1}')
if [ -z $1 ]; then
# Print the plain text password.
echo "plain_text_password = ${PASS}"
# Print the rpc-password string: hash + salt prepended with a curly bracket.
# Source: https://github.com/transmission/transmission/blob/master/libtransmission/crypto-utils.c#L153
echo "rpc_password_string = {${HASH}${SALT}"
else
#Print password hash
echo "{${HASH}${SALT}"
fi