\nSo I dont keep asking you for your email and password everytime you run me, I will be saving an encrypted file at. Print('I could not file the credentials file.
With open(directory+'\\Credentials.txt', 'r') as file: getCredentials will create the encrypted file if it does not exist and return a dictionaty, and updateCredential will update. You basically import or copy the function to your code.
However it does obfuscate, and if you compile the code (with something like Nuitka) at least your password won't appear as plain text in a hex editor. If someone has both the token and the key (as they would if they have the script), they can decrypt easily. Obviously, there are some shortcomings to this approach. Once you've done this, you can either import mypassword directly or you can import the token and cipher to decrypt as needed. Mypassword = crypt(token).decode('utf-8') # create a cipher and decrypt when you need your password Token = b'gAAAAABe_TUP82q1zMR9SZw1LpawRLHjgNLdUOmW31RApwASzeo4qWSZ52ZBYpSrb1kUeXNFoX0tyhe7kWuudNs2Iy7vUwaY7Q=' Key = b'B8XBLJDiroM3N2nCBuUlzPL06AmfV4XkPJ5OKsPZbC4=' Then, create a module with the following code: from cryptography.fernet import Fernet
> password = "thepassword".encode('utf-8')ī'gAAAAABe_TUP82q1zMR9SZw1LpawRLHjgNLdUOmW31RApwASzeo4qWSZ52ZBYpSrb1kUeXNFoX0tyhe7kWuudNs2Iy7vUwaY7Q=' A way that I have done this is as follows:Īt the python shell: > from cryptography.fernet import Fernetī'B8XBLJDiroM3N2nCBuUlzPL06AmfV4XkPJ5OKsPZbC4='