0

I am making a password manager program (as chatGPT suggested) what its supposed to do when you first start is to make the file containing the "Master Password" encrypted, but when I go test the program and enter the new master password, it doesn't make the file.

Here is the code below:

import os
import fernet

# this will be the master password file, which contains the master password, but encrypted using fernet
masterPasswordFile = 'mstrpswd.faiK'
doesMasterPasswordExist = os.path.exists(masterPasswordFile)

# so we can break the program
while True:
    if doesMasterPasswordExist == False: # this is self-explanatory
        print('Looks like it`s your first time, please set up a master password before we gets started.')
        masterPassword = str(input('--> '))
        
        masterPassword_encrypted = fernet.Encrypter(masterPassword) # encrypt master password
        newFile = open(f'{masterPasswordFile}', 'w')
        newFile.write(masterPassword_encrypted) # write the encrpyted password
        newFile.close()
        continue
    elif doesMasterPasswordExist == True:
        print('What is your master password?')
        user_mstrpswd = str(input('--> '))
        mstrpswdFile = open(f'{masterPasswordFile}', 'r') # opens the file
        masterPassword_encrypted_readFromFile = mstrpswdFile.read() # reads the password from file
        mstrpswd_decrypted = fernet.Decrypter(masterPassword_encrypted_readFromFile) # decrypt it.

        if mstrpswd_decrypted != user_mstrpswd:
            print('Thats not right, try again.')
            continue
        else:
            # actual code.
            print('You`re in!')

It's still in the works, but I just wanted to see if it was functioning properly.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • Where have you narrowed the problem down to? You never close the file in one case, which can prevent data from being written. You should be using a `with` block to prevent errors like that. – Carcigenicate Mar 07 '23 at 23:43
  • would you as to kindly show me where i can do so? @Carcigenicate – Bergua Sensusa Mar 07 '23 at 23:45
  • This code causes an error when I run it. If you're getting that, you should always include errors when asking for help. `Encrypter` doesn't take the string to encrypt though. You'll need to look over the module to see how to use it properly. I think you meant to use the `Fernet` class, not `Encryptor`. – Carcigenicate Mar 07 '23 at 23:55
  • I try to use fernet from cryptography.fernet, but it wouldn't work. I also went ahead and tried to install cryptography.fernet, which I believe wasn't a good idea. @Carcigenicate – Bergua Sensusa Mar 08 '23 at 21:31

0 Answers0