# File: validPassword.py # Author: Dr. Gibson # Date: 9/27/2017 # Section: N/A # E-mail: k.gibson@umbc.edu # Description: # This file contains python code that asks the user to # enter a password, with specific requirements needed # in order for the password to be valid MIN_LEN = 8 # minimum length of password MAX_LEN = 20 # maximum length of password def main(): #set up the boolean flag passwordValid = False # this will evaluate to True as long as the password is NOT valid while not passwordValid: # get the password and assume (for now) that it's valid password = input("Please enter a password: ") passwordValid = True # we haven't covered this yet, but this is how string length is done passLen = len(password) # if the password is too short, it's invalid if passLen < MIN_LEN: print("Your password is too short.") passwordValid = False # if the password is too long, it's invalid if passLen > MAX_LEN: print("Your password is too long.") passwordValid = False # if none of these conditionals was True, then passwordValid # will still be True, and the while loop will exit # exited the while loop, so print out the chosen password print("Thanks for picking the super-secure password", password) main()