Python – Hiding a password in a python script (insecure obfuscation only)


I have got a python script which is creating an ODBC connection. The ODBC connection is generated with a connection string. In this connection string I have to include the username and password for this connection.

Is there an easy way to obscure this password in the file (just that nobody can read the password when I'm editing the file) ?

Best Solution

Base64 encoding is in the standard library and will do to stop shoulder surfers:

>>> import base64
>>>  print(base64.b64encode("password".encode("utf-8")))
>>> print(base64.b64decode("cGFzc3dvcmQ=").decode("utf-8"))