Created
January 10, 2012 13:26
-
-
Save qoda/1589086 to your computer and use it in GitHub Desktop.
Generate a random, but somewhat readable password.
This file contains hidden or 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 | |
from random import choice | |
from string import ascii_lowercase, ascii_uppercase, digits | |
from sys import argv | |
VOWELS = ['a', 'e', 'i', 'o', 'u'] | |
CONSONANTS = [l for l in ascii_lowercase if l not in VOWELS] | |
FIRST = choice([l for l in ascii_uppercase if l.lower() not in VOWELS]) | |
def generate_password(length): | |
""" | |
Generate a random, but somewhat readable password. | |
""" | |
random_password = [FIRST] | |
for i in range(length - 2): | |
if i % 2: | |
random_password.append(choice(CONSONANTS)) | |
else: | |
random_password.append(choice(VOWELS)) | |
random_password.append(choice(digits)) | |
return "".join(random_password) | |
if __name__ == '__main__': | |
try: | |
password_length = int(argv[1]) | |
except IndexError: | |
password_length = 8 | |
print generate_password(password_length) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Neat!