Skip to content

Instantly share code, notes, and snippets.

@cnicodeme
Last active October 9, 2019 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cnicodeme/32bfcda65e642204cf2f5f87d94fa612 to your computer and use it in GitHub Desktop.
Save cnicodeme/32bfcda65e642204cf2f5f87d94fa612 to your computer and use it in GitHub Desktop.
Generates a sha256 hash of a username:password credentials for secured basic HTTP authentication.
#!/usr/bin/python
import sys, hashlib, base64
# USAGE: ./token.py "username" "password"
if len(sys.argv) != 3:
print("USAGE: script.py username password")
exit(1)
def generate(username, password):
return hashlib.sha256(base64.b64encode('{0}:{1}'.format(username, password).encode())).hexdigest()
print('Your token:')
print(generate(sys.argv[1], sys.argv[2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment