Genearte Complex Password

from os import urandom
from random import choice

char_set = {'small': 'abcdefghijklmnopqrstuvwxyz',
'nums': '0123456789',
'special': '^!$%&/()=?{[]}+~#-_.:,;<>|'}

length = raw_input("Enter number of letters: ")
length = int(length)

def generate_pass(length):
"""Function to generate a password"""

password = []

while len(password) < length:
key = choice(char_set.keys())
a_char = urandom(1)
if a_char in char_set[key]:
if check_prev_char(password, char_set[key]):
return ''.join(password)

def check_prev_char(password, current_char_set):
"""Function to ensure that there are no consecutive

index = len(password)
if index == 0:
return False
prev_char = password[index - 1]
if prev_char in current_char_set:
return True
return False

print "The password is " + generate_pass(length)
This entry was posted in Python and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s