XKCD Password Generator

1.30.0 · active · verified Fri Apr 17

xkcdpass is a Python library that generates secure multiword passwords or passphrases inspired by the XKCD comic 'Password Strength'. It provides tools to create memorable yet strong passphrases using various wordlists and configuration options. The library is actively maintained with a consistent release cadence, with the current version being 1.30.0.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to generate a strong, memorable passphrase using the bundled wordlist. It first locates the wordlist, processes it to meet specific length criteria, and then generates a 4-word passphrase using a hyphen as a separator.

import xkcdpass.xkcd_password as xp

# Locate the default bundled wordlist
wordlist_path = xp.locate_wordlist()

# Generate a wordlist from the file
# You can also specify language or min/max word length here
wordlist = xp.generate_wordlist(wordlist=wordlist_path, min_length=5, max_length=8)

# Generate a passphrase with 4 words and a hyphen separator
passphrase = xp.generate_xkcdpassword(wordlist, numwords=4, separator='-')
print(f"Generated Passphrase: {passphrase}")

view raw JSON →