Created
June 25, 2012 00:38
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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