Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Generate a password/passphrase that is just many words strung together
"""Generate n-word (default n=5) passwords separated by sep (default '-').
Uses your friendly neighborhood words file by default.
Simple Use: `python`
Help: `python --help`
import argparse
import random
parser = argparse.ArgumentParser(
description='Generate n-word passwords separated by sep.')
parser.add_argument('-n', type=int, default=5,
help='Number of words (default 5)')
parser.add_argument('-s', '--sep', type=str, default='-',
help='Separator for words (default "-")')
'--wf', type=str,
help='Path to words file (default "/usr/share/dict/words")')
args = parser.parse_args()
n, sep, wf = args.n, args.sep,
with open(wf) as f:
lines = f.readlines()
words = set(line.strip().lower() for line in lines)
result = sep.join(random.sample(words, n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment