XKCD Password Generator
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
-
ModuleNotFoundError: No module named 'xkcdpass'
cause The xkcdpass library is not installed in your current Python environment.fixRun `pip install xkcdpass` to install the library. -
AttributeError: module 'xkcdpass' has no attribute 'generate_xkcdpassword'
cause You likely imported `xkcdpass` directly instead of its submodule `xkcd_password`, where the core functions reside.fixChange your import statement to `import xkcdpass.xkcd_password as xp` and then call functions like `xp.generate_xkcdpassword()`. -
FileNotFoundError: [Errno 2] No such file or directory: '<path_to_your_wordlist>'
cause The path provided to `generate_wordlist` or `locate_wordlist` does not point to an existing wordlist file.fixEnsure the path to your custom wordlist is correct and the file exists. If using the bundled wordlist, ensure `xp.locate_wordlist()` is called correctly and that the library was installed properly to include its data files.
Warnings
- breaking The default separator character for `generate_xkcdpassword` changed from a space (' ') to a hyphen ('-') in version 1.0.0.
- gotcha Using a small or unsecure wordlist (e.g., custom wordlists with few unique words, or dictionary words easily guessable) significantly compromises the security of generated passphrases.
- gotcha The `generate_wordlist` function returns a `list` of words, not a `set` (which was the case in some older implementations/examples).
Install
-
pip install xkcdpass
Imports
- xkcd_password
import xkcdpass
import xkcdpass.xkcd_password as xp
Quickstart
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}")