Python/Django - Avoid saving passwords in source code

前端 未结 4 573
悲&欢浪女
悲&欢浪女 2021-01-29 23:44

I use Python and Django to create web applications, which we store in source control. The way Django is normally set up, the passwords are in plain text within the settings.py f

4条回答
  •  梦谈多话
    2021-01-30 00:14

    Having something like this in your settings.py:

    db_user = 'my_db_user' db_password = 'my_db_password'

    Hard codes valuable information in your code and does pose a security risk. An alternative is to store your valuable information (Api keys, database passwords etc.) on your local machine as environment variables. E.g. on linux you could add:

    export DB_USER = "my_db_user" export DB_PASS = "my_db_password"

    to your .bash_profile. Or there is usually an option with your hosting provider to set environment variables e.g. with AWS elastic beanstalk you can add env variables under your configuration on console.

    Then to retrieve your information import os:

    import os db_user = os.environ.get['DB_USER'] db_password = os.environ.get['DB_PASS']

提交回复
热议问题