pythonpassword-protectionpassword-encryption

How to hide my login and password in the python script?


How can i not show the login ID and password in the python script?

Is there any library or command can I hide those information?

For example:

login_id = "secret_id" instead of login_id = "ABC@gmail.com"

password = "secret_password" instead of password = "1234ABCD"


Solution

  • You can use environment variables to decouple credentials and other sensitive content from your Python scripts.

    import os
    
    # Get environment variables
    login_id = os.getenv('MY_LOGIN_ID')
    password = os.environ.get('MY_PASSWORD')
    

    You can configure this on OS level using

    export MY_LOGIN_ID="my login"
    export MY_PASSWORD="my password"