Skip to content

Instantly share code, notes, and snippets.

@dwinston
Created April 3, 2017 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwinston/d7e696406c0aed59fcf56f6ef9f85c6d to your computer and use it in GitHub Desktop.
Save dwinston/d7e696406c0aed59fcf56f6ef9f85c6d to your computer and use it in GitHub Desktop.
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