Skip to content

Instantly share code, notes, and snippets.

@cnicodeme

cnicodeme/token.py

Last active Oct 9, 2019
Embed
What would you like to do?
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