libkeepass / pykeepass

Python library to interact with keepass databases (supports KDBX3 and KDBX4)
https://pypi.org/project/pykeepass/
GNU General Public License v3.0
411 stars 96 forks source link

What's the right way to change the master password? #304

Closed rtl19 closed 2 years ago

rtl19 commented 2 years ago

I'm probably doing this wrong. I tried changing the master password using the following: keepass.password = newpasswordstring

However, doing so gives me the following error: `line 114, in compute_key_composite

password_composite = hashlib.sha256(password.encode("utf-8")).digest()

AttributeError: "tuple" object has no attribute "encode"`

The worst part is it totally corrupts the database file from this point.

Evidlo commented 2 years ago

Can you give more information, like your OS and pykeepass version? I'm not able to reproduce this.

>>> from pykeepass import PyKeePass; kp = PyKeePass('test4.kdbx', 'password', 'test4.key')
>>> kp.password
'password'
>>> kp.password = 'password1'
>>> kp.save()
>>> from pykeepass import PyKeePass; kp = PyKeePass('test4.kdbx', 'password1', 'test4.key')
Evidlo commented 2 years ago

Are you sure that newpasswordstring is actually a string and not a tuple?

rtl19 commented 2 years ago

Hi @Evidlo , I'm using python 3.8 on Windows 10 using the latest installed pykeepass pip. Unfortunately, I won't be able to give you the actual version number until Monday. I also tried this using python 3.6 and had the same error. i'm fairly certain newpasswordstring is actually a string but I'll double check that as well. I'll also specifically cast it to a string as a test.

Evidlo commented 2 years ago

I get the same result as you when I try to set the password to something that isn't a string. I've fixed the database clobbering issue in 4.0.2

rtl19 commented 2 years ago

@Evidlo , the tuple problem was in my code. Thank you for helping me find it.