Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Password:
- #right here you need to set an initializer
- #using the __init__ dunder
- #the password and the message are the only two variables that need
- #to be initialized everything else can be contained in the isValid() method
- valid = True #all of these need to be private (IE. self.__one)
- one = True
- two = True
- three = True
- four = True
- five = True
- def setPassword(self): #all of your checkers need to be in a single function called isValid()
- self.__user_password()
- def checkOne(self):
- if len(user_password #putting user in front of ) < 8:
- one = False
- valid = False
- def checkTwo(self):
- # Make sure only consists of letters and digits.
- # The isalnum returns True only if the password consists of letters and numbers.
- if not user_password.isalnum():
- two = False
- valid = False
- def checkThree():
- # Make sure the password has at least two digits
- digit_count = 0
- for char in user_password:
- if char.isdigit():
- digit_count += 1
- if digit_count < 2:
- three = False
- valid = False
- def checkFour():
- # Make sure the password does not contain the word password
- if "password" in user_password:
- four = False
- valid = False
- def checkFive():
- passwordList = user_password.split()
- if passwordList[-1, -3] == 321:
- five = False
- valid = False
- def isValid(self):
- self.__checkOne()
- self.__checkTwo()
- self.__checkThree()
- self.__checkFour()
- self.__checkFive()
- def getErrorMessage(self):
- # This should return a string that indicates all problems with the password
- print("Password is invalid")
- if valid == False: #the block of code that generates the error message needs to be included in isValid()
- if one == False:
- message += "Must have 8 characters.\n"
- elif two == False:
- message += "Must consist of numbers and letters.\n"
- elif three == False:
- message += "Must have at least two numbers.\n"
- elif four == False:
- message += "Cannot include the word password.\n"
- elif five == False:
- message += "Cannot have 123 at the end.\n"
- # This function should be called if isValid returns False.
- # The isValid() method can generate this string as it sets each password requirement.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement