Last active
May 26, 2017 12:39
-
-
Save Limerin555/3578e123c63549099bed1d13f5bff73b to your computer and use it in GitHub Desktop.
Attempting exercises from Practice Python( http://www.practicepython.org/ )
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
# Write a password generator in Python. Be creative with how you generate passwords - 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. | |
# | |
# Extra: | |
# | |
# Ask the user how strong they want their password to be. For weak passwords, pick a word or two from a list. | |
userin = input("Would you like a strong or weak password? ") | |
userin = userin.lower() | |
import string | |
import random | |
def generatePW(): | |
""" | |
Evaluate if user wants a weak or strong password, before passing it respective password generator. | |
""" | |
if userin == "weak": | |
print(weakPW()) | |
elif userin == "strong": | |
print(strongPW()) | |
else: | |
print("Invalid input! Type 'Weak' or 'Strong' to generate a password.") | |
def weakPW(size = 6, chars = string.ascii_lowercase + string.digits): | |
""" | |
Will generate a weak password if user input matches. | |
""" | |
weak_pass = "".join(random.SystemRandom().choice(chars) for _ in range(size)) | |
return "Your weak password is {}, please keep it with you at all times.".format(weak_pass) | |
def strongPW(size = 12, chars = string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuation): | |
""" | |
Will generate a strong password if user input matches. | |
""" | |
strong_pass = "".join(random.SystemRandom().choice(chars) for _ in range(size)) | |
return "Your strong password is {}, please keep it with you at all times.".format(strong_pass) | |
generatePW() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment