#Its broken

11 messages · Page 1 of 1 (latest)

robust prism
#

I dont know why this is broken, but it is...

from cryptography.fernet import Fernet

'''
def write_key():
key = Fernet.generate_key()
with open('key.key', 'wb') as key_file:
key_file.write(key)'''

def load_key():
file = open('key.key', 'rb')
key = file.read()
file.close()
return key

main_password = input('What is the password? ')
key = load_key() + main_password.encode()
fer = Fernet(key)

def view():
with open('passwords.txt', 'r') as f:
for line in f.readlines():
data = line.rstrip()
user, pwd = data.split("|")
print("Username:", fer.decrypt(user.encode().decode()), "| Password:", fer.decrypt(pwd.encode().decode()))

def add():
name = input('Define account name: ')
password = input('Define account password: ')

with open('passwords.txt', 'a') as f:
    f.write(fer.encrypt(name.encode).decode() + "|" + fer.encrypt(password.encode).decode() + "\n")

while True:
mode = input('Would you like to add a password, or view existing passwords (view, add)? Press "q" if you would like to quit. ').lower()
if mode == 'q':
break

if mode == 'view':
    view()
elif mode == 'add':
    add()
else:
    print("Invalid mode, please try again.")
    continue
zenith chasm
#

Do you get an error? What part of it is broken?

robust prism
zenith chasm
#

Am issue in what way? Are you getting an error? I'm not familiar with the package you're using

robust prism
# zenith chasm Am issue in what way? Are you getting an error? I'm not familiar with the packag...

File "c:\Users(placeholder)\OneDrive\Documents\Python\Pwd_Manager.py", line 41, in <module>
add()
File "c:\Users(placeholder)\OneDrive\Documents\Python\Pwd_Manager.py", line 31, in add
f.write(fer.encrypt(name.encode).decode() + "|" + fer.encrypt(password.encode).decode() + "\n")
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users(placeholder)\AppData\Local\Programs\Python\Python311\Lib\site-packages\cryptography\fernet.py", line 52, in encrypt
return self.encrypt_at_time(data, int(time.time()))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users(placeholder)\AppData\Local\Programs\Python\Python311\Lib\site-packages\cryptography\fernet.py", line 56, in encrypt_at_time
return self._encrypt_from_parts(data, current_time, iv)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users(placeholder)\AppData\Local\Programs\Python\Python311\Lib\site-packages\cryptography\fernet.py", line 61, in _encrypt_from_parts
utils._check_bytes("data", data)
File "C:\Users(placeholder)\AppData\Local\Programs\Python\Python311\Lib\site-packages\cryptography\utils.py", line 31, in _check_bytes
raise TypeError(f"{name} must be bytes")
TypeError: data must be bytes

quiet willow
#

Your strings need to be bytes, doing b"" should solve them

#

But again why are you diving into cryptography and stuff this early on?

robust prism
robust prism
#

its too complicated to me

sand tapir
#

Typehints are very powerful