# Write a password generator in Python.
# strong passwords have a mix of lowercase letters, 
# uppercase letters, numbers, and symbols.
# The passwords should be random, generating a new password 
# every time the user asks for a new password.
# Include your run-time code in a main method.


import string
import random

characters = string.ascii_letters
chartest = [characters[i] for i in range(len(characters))]
digits = string.digits
special = string.punctuation
randomValue = characters + digits + special


def createpassword(randomValue, passlen):
    password = ''.join(random.sample(randomValue, passlen))
    return password


def mainstart():
    passlen = int(input("Enter the length of your password greater than 6: "))
    if passlen < 6:
        print("Password should be greater than 6. Retry!")
        mainstart()
    else:
        password = createpassword(randomValue, passlen)
        print(password)
        reqagain = input("Want to try again? Y/N ").lower()
        if reqagain == 'y':
            mainstart()
        else:
            quit()


mainstart()
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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