Skip to content

Instantly share code, notes, and snippets.

@Limerin555
Created May 26, 2017 12:38
Show Gist options
  • Save Limerin555/9f92496e282ebe243fc1b2305002be09 to your computer and use it in GitHub Desktop.
Save Limerin555/9f92496e282ebe243fc1b2305002be09 to your computer and use it in GitHub Desktop.
Attempting exercises from Practice Python( http://www.practicepython.org/ )
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