Skip to main content

Generate a cryptographically secure, random, eight-character alphanumeric password in python.

#!/usr/bin/env python3

import string
import secrets


#
# Generate a secure, random, eight-character alphanumeric password
# https://docs.python.org/3/library/secrets.html#recipes-and-best-practices
#

alphabet = string.ascii_letters + string.digits
password = ''.join(secrets.choice(alphabet) for i in range(8))