Hiding passwords in python file

714 Views Asked by At

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?

1

There are 1 best solutions below

0
Dolan On

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