Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to securely store database password in Python? [closed]

In PHP the accepted way to secure database login credentials is to store them outside the web root, and to include() the files with the passwords. How are MySQL database login credentials safely stored in Python applications?

like image 863
dotancohen Avatar asked Jun 26 '13 15:06

dotancohen


People also ask

How do you hide a hardcoded password in Python?

In Python with the help of maskpass() module and base64() module we can hide the password of users with asterisk(*) during input time and then with the help of base64() module it can be encrypted.

Can we store encrypted password in a database?

Encrypted passwordsIn some cases, passwords are stored in a database after being encrypted by a reversible algorithm (rot13, mask encryption…).


1 Answers

Well, one way of doing this is putting the passwords in a separate config/ini file that is not deployed with the project. And then, pass the path of this file to the main entry of the application, e.g.:

python main.py --config=/path/to/config.ini

Note that you'll need to parse this --config argument (see argparse) and then read and parse the config.ini file.

Update: Since you mentioned web applications, there is also another way of passing configuration information - through the environ. For example, if you use mod_wsgi, you can putt this in the wsgi directives:

SetEnv my_namespace.some_param some_value

And then, this value will be accessible in the application with through os.environ:

import os
os.environ['my_namespace.some_param']
like image 66
vonPetrushev Avatar answered Sep 18 '22 15:09

vonPetrushev