Skip to content

Commit 5a00089

Browse files
committed
Refactor PBKDF2 hash generation for improved readability and efficiency
1 parent c981510 commit 5a00089

File tree

1 file changed

+6
-19
lines changed
  • root/etc/s6-overlay/s6-rc.d/init-qbittorrent-config

1 file changed

+6
-19
lines changed

root/etc/s6-overlay/s6-rc.d/init-qbittorrent-config/run

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,13 @@ fi
2424

2525
# function to generate PBKDF2 hash exactly like qBittorrent source code
2626
generate_pbkdf2_hash() {
27-
local password="$1"
28-
echo "$password" | python3 -c "
29-
import hashlib
30-
import os
31-
import base64
32-
import sys
33-
34-
# Read password from stdin
35-
password = sys.stdin.read().rstrip('\n')
36-
37-
# Generate 16 bytes of random salt
27+
echo "$1" | python3 -c "
28+
import os, sys, base64, hashlib
29+
password = sys.stdin.read().rstrip('\n').encode()
3830
salt = os.urandom(16)
39-
40-
# Generate PBKDF2 hash with exactly qBittorrent's parameters
41-
hash_bytes = hashlib.pbkdf2_hmac('sha512', password.encode('utf-8'), salt, 100000, 64)
42-
43-
# Format exactly like qBittorrent: saltView.toBase64() + ':' + outBufView.toBase64()
44-
salt_b64 = base64.b64encode(salt).decode('ascii')
45-
hash_b64 = base64.b64encode(hash_bytes).decode('ascii')
46-
31+
hash_bytes = hashlib.pbkdf2_hmac('sha512', password, salt, 100000, 64)
32+
salt_b64 = base64.b64encode(salt).decode()
33+
hash_b64 = base64.b64encode(hash_bytes).decode()
4734
print(f'{salt_b64}:{hash_b64}')
4835
"
4936
}

0 commit comments

Comments
 (0)