Page 1 of 1
qBittorrent password generator script
Posted: Fri Apr 10, 2020 1:09 am
by qBLover
Hi all,
Can someone please help me with a short python script/bash script that can generate PBKDF2 hash for qbittorrent?
I can see the code here --
https://github.com/qbittorrent/qBittorr ... ssword.cpp
But I don't know enough C++/crypto to replicate this.
Thanks for the help in advance.
P.S - I am not trying to reset my password, I am trying to make my password reset bit easier. I prefer typing a command rather than edit configuration, restart etc. :-)
Re: qBittorrent password generator script
Posted: Fri Mar 03, 2023 7:29 am
by 57d6f0
Hi,
Sorry for the necrobump, but for the records I also needed this (for a different reason than OP), so I came up with the following python script to generate hashes suitable for QBittorrent config file:
Code: Select all
import base64
import getpass
import hashlib
import os
# As per https://github.com/qbittorrent/qBittorrent/blob/ce9bdaef5cdb8ab77d71481f20b25c9e6da1b9eb/src/base/utils/password.cpp#L48
ITERATIONS = 100_000
# 4x32 bits words = 16 bytes: https://github.com/qbittorrent/qBittorrent/blob/ce9bdaef5cdb8ab77d71481f20b25c9e6da1b9eb/src/base/utils/password.cpp#L75
SALT_SIZE = 16
# Prompt user for password
password = getpass.getpass()
# Generate a cryptographically secure pseudorandom salt
salt = os.urandom(SALT_SIZE)
# PBKDF2 w/ SHA512 hmac
h = hashlib.pbkdf2_hmac("sha512", password.encode(), salt, ITERATIONS)
# Base64 encode and join salt and hash
print(f"Hash: {base64.b64encode(salt).decode()}:{base64.b64encode(h).decode()}")
To sum it up, it's a standard PBKDF2 with a SHA512 hmac, 100.000 iterations, and a 128bits salt. The salt is base64 encoded as well as the hash, and the two are joined together with the "
:" character (probably in an external config serialization step). The resulting string can be used directly in config like so:
Code: Select all
WebUI\Password_PBKDF2="@ByteArray(<hash as returned by the script>)"
so in practice, "
password123" coud be (depending on the salt):
Code: Select all
WebUI\Password_PBKDF2="@ByteArray(q+12KDUV69nIdoK92Alh7Q==:HtvIsWsCSN9PnE/gayIruCDeDjnz8TXG+Cw2XUTWs1CJFRXQxyyOyz/FVyU9QtTgEJ9fwxZYJKHaURV42sB0JQ==)"
Hope that'll help someone. Maybe not. Maybe future me

.
Re: qBittorrent password generator script
Posted: Tue Apr 18, 2023 12:03 am
by lpineda
It did help me!
I made an ansible custom filter to configure qBittorrent UI password.
This is the custom filter, just place it under the folder
filter_plugins.
Code: Select all
#!/usr/bin/python
import base64
import hashlib
import os
class FilterModule(object):
def filters(self):
return {'qbittorrent_passwd': self.qbittorrent_passwd}
def qbittorrent_passwd(self, plain_passwd):
# As per https://github.com/qbittorrent/qBittorrent/blob/ce9bdaef5cdb8ab77d71481f20b25c9e6da1b9eb/src/base/utils/password.cpp#L48
ITERATIONS = 100_000
# 4x32 bits words = 16 bytes: https://github.com/qbittorrent/qBittorrent/blob/ce9bdaef5cdb8ab77d71481f20b25c9e6da1b9eb/src/base/utils/password.cpp#L75
SALT_SIZE = 16
# Generate a cryptographically secure pseudorandom salt
salt = os.urandom(SALT_SIZE)
# PBKDF2 w/ SHA512 hmac
h = hashlib.pbkdf2_hmac("sha512", plain_passwd.encode(), salt, ITERATIONS)
# Base64 encode and join salt and hash
return f"@ByteArray({base64.b64encode(salt).decode()}:{base64.b64encode(h).decode()})"
Sample task. Note that
qbittorrent_ui_passwd is a variable on ansible
hosts file.
Code: Select all
- name: Set qBittorrent 'WebUI\Password_PBKDF2'
ini_file:
path: '{{ mount_path }}/config/qBittorrent.conf'
owner: '{{ 1000 | int }}'
group: '{{ 1000 | int }}'
mode: '0664'
section: Preferences
option: WebUI\Password_PBKDF2
value: '{{ qbittorrent_ui_passwd | qbittorrent_passwd }}'
Re: qBittorrent password generator script
Posted: Wed May 10, 2023 7:15 am
by Natasha78
qBLover wrote: ↑Fri Apr 10, 2020 1:09 am
Hi all,
Can someone please help me with a short python script/bash script that can generate PBKDF2 hash for qbittorrent?
I can see the code here --
https://github.com/qbittorrent/qBittorr ... ssword.cpp
But I don't know enough C++/crypto to replicate this.
Thanks for the help in advance.
P.S - I am not trying to reset my password, I am trying to make my password reset bit easier. I prefer typing a command rather than edit configuration, restart etc. :-)
Thank you,
for sharing such good information, and for lots of love,and amazing things that you have contributed.
Fm Whatsapp download