Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. class Password:
  2. #right here you need to set an initializer
  3. #using the __init__ dunder
  4. #the password and the message are the only two variables that need
  5. #to be initialized everything else can be contained in the isValid() method
  6.  
  7. valid = True #all of these need to be private (IE. self.__one)
  8. one = True
  9. two = True
  10. three = True
  11. four = True
  12. five = True
  13.  
  14. def setPassword(self): #all of your checkers need to be in a single function called isValid()
  15. self.__user_password()
  16.  
  17. def checkOne(self):
  18. if len(user_password #putting user in front of ) < 8:
  19. one = False
  20. valid = False
  21.  
  22. def checkTwo(self):
  23. # Make sure only consists of letters and digits.
  24. # The isalnum returns True only if the password consists of letters and numbers.
  25. if not user_password.isalnum():
  26. two = False
  27. valid = False
  28.  
  29. def checkThree():
  30. # Make sure the password has at least two digits
  31. digit_count = 0
  32. for char in user_password:
  33. if char.isdigit():
  34. digit_count += 1
  35. if digit_count < 2:
  36. three = False
  37. valid = False
  38.  
  39. def checkFour():
  40. # Make sure the password does not contain the word password
  41. if "password" in user_password:
  42. four = False
  43. valid = False
  44.  
  45. def checkFive():
  46. passwordList = user_password.split()
  47. if passwordList[-1, -3] == 321:
  48. five = False
  49. valid = False
  50.  
  51. def isValid(self):
  52. self.__checkOne()
  53. self.__checkTwo()
  54. self.__checkThree()
  55. self.__checkFour()
  56. self.__checkFive()
  57.  
  58. def getErrorMessage(self):
  59. # This should return a string that indicates all problems with the password
  60.  
  61. print("Password is invalid")
  62. if valid == False: #the block of code that generates the error message needs to be included in isValid()
  63.  
  64. if one == False:
  65. message += "Must have 8 characters.\n"
  66. elif two == False:
  67. message += "Must consist of numbers and letters.\n"
  68. elif three == False:
  69. message += "Must have at least two numbers.\n"
  70. elif four == False:
  71. message += "Cannot include the word password.\n"
  72. elif five == False:
  73. message += "Cannot have 123 at the end.\n"
  74.  
  75. # This function should be called if isValid returns False.
  76.  
  77. # The isValid() method can generate this string as it sets each password requirement.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement