Skip to content

Instantly share code, notes, and snippets.

@quodlibetor
Created June 25, 2012 00:38
Show Gist options
  • Save quodlibetor/2985716 to your computer and use it in GitHub Desktop.
Save quodlibetor/2985716 to your computer and use it in GitHub Desktop.
A simple password generator that works on *nix, and generates passwords out of real words.
#!/usr/bin/env python
# author: Brandon W Maister
# This file is in the public domain
"""Create passwords using random words
Long passwords are better than short, a long (20+ char) password made of
whole words is better than a short one, unless the attacker knows that you're
using whole words.
This is good enough for me.
"""
import sys
try:
from random import SystemRandom
random = SystemRandom()
except ImportError:
print 'weak random numbers'
import random
def makepass(min_len=20):
with open('/usr/share/dict/words') as fh:
words = fh.readlines()
password = ''
while len(password) < min_len:
password += random.choice(words).lower().strip() + ' '
return password.strip()
if __name__ == '__main__':
if len(sys.argv) > 1:
try:
print makepass(int(sys.argv[1]))
except ValueError:
print "Only argument is the minimum length for the password"
else:
print makepass()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment