Last active
January 6, 2016 12:42
-
-
Save ishahid/54f0478e480234fa44ec to your computer and use it in GitHub Desktop.
Generates a random API key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
"""Generate a random API key | |
https://gist.github.com/ishahid/54f0478e480234fa44ec | |
""" | |
import base64 | |
import hashlib | |
import random | |
def generate_key(): | |
random_hash = hashlib.sha256(str(random.getrandbits(256))).digest() | |
random_chars = random.choice(['rA', 'aZ', 'gQ', 'hH', 'hG', 'aR', 'DD']) | |
return base64.b64encode(random_hash, random_chars).rstrip('==') | |
if __name__ == "__main__": | |
key = generate_key() | |
print key |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment