Skip to content

Instantly share code, notes, and snippets.

Embed
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 nwordspass.py`
Help: `python nwordspass.py --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 "-")')
parser.add_argument(
'--wf', type=str,
default='/usr/share/dict/words',
help='Path to words file (default "/usr/share/dict/words")')
args = parser.parse_args()
n, sep, wf = args.n, args.sep, args.wf
with open(wf) as f:
lines = f.readlines()
words = set(line.strip().lower() for line in lines)
result = sep.join(random.sample(words, n))
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment