I have a Python application that has a file containing several hardcoded databases credentials. I have to find a way to hide these information, because keeping usernames and passwords in the code is insecure. I came across Keyring library which could be an alternative, but it also allows an unauthorized developer to print passwords throw the get_password method. Does anyone have any tips for hiding or encrypting passwords in Python, preventing them from printing?
Asked
Active
Viewed 530 times
2
-
1How should that work? The decrypted password should be available in your code (for authentication) but not available (for printing) at the same time. – Klaus D. Nov 10 '21 at 04:38
-
@KlausD. Not actually. What really matters is to hide those passwords. Whether with encryption or otherwise. I don't want anyone who opens the script to be able to access the passwords. Any suggestions? – Borgesj Nov 11 '21 at 21:32
-
2Maybe my response was too complex. I'll shorten it to: not possible. What is possible is to increase the time needed to retrieve the credentials to maybe a few minutes. – Klaus D. Nov 11 '21 at 21:56
1 Answers
0
I would suggest putting your passwords into a .env
file and adding it to your .gitignore
.
Have a look at this write up, it might help you with keeping credentials safe.
https://able.bio/rhett/how-to-set-and-get-environment-variables-in-python--274rgt5

Dolan
- 313
- 1
- 4
- 14