Skip to content

Instantly share code, notes, and snippets.

@emperorcezar
Created October 13, 2011 19:31
Show Gist options
  • Select an option

  • Save emperorcezar/1285259 to your computer and use it in GitHub Desktop.

Select an option

Save emperorcezar/1285259 to your computer and use it in GitHub Desktop.
Generate a password using random words from words.txt
import os
import random
class WordGenerator(object):
def __init__(self):
current_directory = os.path.dirname(os.path.abspath( __file__ ))
words_file = open("%s/words.txt" % (current_directory), 'r')
self.words = words_file.readlines()
words_file.close()
def random_word(self, min_length = 0):
word = random.choice(self.words).strip()
while len(word) < min_length:
word = random.choice(self.words).strip()
return word
def generate_password(length = 8, chars = None, words = 3):
generator = WordGenerator()
password = ''
for i in range(0, words):
password += generator.random_word(min_length = length).capitalize()
password += random.choice('0123456789')
return password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment