Skip to content

Instantly share code, notes, and snippets.

@lordloh
Last active May 15, 2021 02:58
Show Gist options
  • Save lordloh/4a7047049a522570642fd9d941890222 to your computer and use it in GitHub Desktop.
Save lordloh/4a7047049a522570642fd9d941890222 to your computer and use it in GitHub Desktop.
A snippet to avoid hard coding user names and passwords in python scripts.
# If you hardcode usernames and passwords, you cannot check in the code to public git repositories.
# A solution I am using is to create a `credentials.json` file and storing the password there
# cerdentials.json :
# {
# "user":"bharath",
# "password":"bharath_secret_password"
# }
#
# add this file to .gitignore
#
# This file my be protected on apache web server using -
# <Files ~ "\credentials.json$">
# Require all denied
# </Files>
import json
with open('credentials.json') as json_data:
credentials = json.load(json_data)
login(username=credentials['user'] password=credentials['password']")
@CavalcanteLucas
Copy link

nice!! thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment