Guest User

Untitled

a guest
Sep 14th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. # Import Python's system functionality module for the exit function when passwords are wrong
  2. import sys
  3.  
  4. # Import Python's regular expressions library, popularly known as Regex
  5. import re
  6.  
  7.  
  8. # Prompt the user to enter their userName, the userName input will be type converted to str
  9. userName = str(input("\n\tPlease input your username: \n\n\t"))
  10.  
  11. # Print a welcome message string formated to includ the username
  12. print("\n\t Welcome: {}\n".format(userName))
  13.  
  14. # Prompt the user to enter a passWord, input will be type converted to str for regex manipulation
  15. passWord = str(input("\n\tPlease enter a password.\n\n\t Type here: "))
  16.  
  17.  
  18. # Test to see whether the user enters a series of comma separated passWords
  19. # Do this by testing the passWord string for the presence of a comma
  20. # If there's a comma in the passwords sequence, split up the string by comma
  21. if "," in passWord:
  22.  
  23. # Create a list called passWordsList that will hold the passWords
  24. passWordsList = passWord.split(",")
  25.  
  26. # The passWord is the value in passWordsList[0]
  27. passWord = passWordsList[0]
  28.  
  29. # The invalidPassWordMessage string is to be printed on the screen if the password in invalid
  30. invalidPasswordMessage = """
  31. Your password is invalid.The password must have:
  32.  
  33. 1. At least 1 letter between [a-z]
  34. 2. At least 1 number between [0-9]
  35. 3. At least 1 letter between [A-Z]
  36. 4. At least 1 character from [$#@]
  37. 5. Minimum length of transaction password: 6
  38. 6. Maximum length of transaction password: 12
  39.  
  40. """
  41.  
  42. # Create a boolean test for the validity of the password, with value False
  43. passwordTest = False
  44. while passwordTest:
  45.  
  46. # Using the regex library search method test if lower case letters are
  47. # present in the passWord string, the first arguement of the search method
  48. # is the pattern and the second arguement is the string to be tested
  49. if re.search("[a-z]", passWord) == False:
  50. # If the passWord string does not have lower case characters[a-z]
  51. # print the invalidPasswordMessage
  52. print("{}".format(invalidPasswordMessage))
  53. # Exit the application
  54. sys.exit()
  55. elif re.search("[0-9]", passWord) == False:
  56. # If the passWord string does not have any digit from [0-9]
  57. # print the invalidPasswordMessage
  58. print("{}".format(invalidPasswordMessage))
  59. # Exit the application
  60. sys.exit()
  61. elif re.search("[A-Z]", passWord) == False:
  62. # If the passWord string does not have upper case characters [A-Z]
  63. # print the invalidPasswordMessage
  64. print("{}".format(invalidPasswordMessage))
  65. # Exit the application
  66. sys.exit()
  67. elif re.search("[$#@]", passWord) == False:
  68. # If the passWord string does not have the special characters [$#@]
  69. # print the invalidPasswordMessage
  70. print("{}".format(invalidPasswordMessage))
  71. # Exit the application
  72. sys.exit()
  73. elif (len(passWord) < 6 or len(passWord)>12):
  74. # If the passWord string does not meet length specifications
  75. # print the invalidPasswordMessage
  76. print("{}".format(invalidPasswordMessage))
  77. # Exit the application
  78. sys.exit()
  79. else:
  80. # If all the passWord conditions have been met, print the username and password
  81. print("\n\t {}, your password is: {}".format(userName, passWord))
  82. # Exit the application
  83. sys.exit()
Add Comment
Please, Sign In to add comment