Skip to content

Instantly share code, notes, and snippets.

@bulatie
Last active May 10, 2019 04:23
Show Gist options
  • Save bulatie/fdd1e6da521b2c90fcb6285401eaf4e9 to your computer and use it in GitHub Desktop.
Save bulatie/fdd1e6da521b2c90fcb6285401eaf4e9 to your computer and use it in GitHub Desktop.
genereate token
# python2
import os
import string
charset = string.ascii_uppercase + string.digits
random_bytes = os.urandom(25)
len_charset = len(charset)
indices = [int(len_charset * (ord(byte) / 256.0)) for byte in random_bytes]
defaultToken = "".join([charset[index] for index in indices])
# python3
"".join(secrets.choice(string.ascii_uppercase + string.digits) for i in range(25))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment