HOW #8 – How to hide your passwords in python code (Windows OS)

It is pretty common for robots to use login and passwords for accessing numerous systems. This should be used by everyone, who plans to store the code on Github and does not want to expose the passwords. In order to hide them in the code, you need to store them elsewhere.

Today I will show method, which stores sensitive data in Windows Credentials. I will use python library keyring to store and get passwords from Windows Credentials.

This code needs to be run separately before. If you plan to use it on more machines, you have to run it on every one.

import keyring

keyring.set_password("keyring_service_name", "[email protected]", "abc")

From now, the password is stored in windows credentials manager

In order to get stored password I will run the code below:

import keyring

pw = keyring.get_password("keyring_service_name", "[email protected]")
print(pw)

The password is stored in pw variable and could be used later for accessing systems.

This should be the very first step when you are starting with securing your automation scripts. Next could be start of using of passwords manager, e.g. LastPass.