Advertisement
Guest User

Untitled

a guest
Jan 15th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. def mainMenu():
  2. print("""
  3. ###############################################################################
  4. # #
  5. # Clive's Carpets #
  6. # Please Login Below! #
  7. # #
  8. ###############################################################################
  9. """)
  10. validateUser()
  11.  
  12. def adminMenu():
  13. while True:
  14. print("""
  15. ###############################################################################
  16. # #
  17. # Clive's Carpets #
  18. # Admin Menu #
  19. # #
  20. # 1 - Add a New User #
  21. # 2 - Exit #
  22. # #
  23. ###############################################################################
  24. """)
  25.  
  26. adminMenu = input('Which option would you like to choose? "1" or "2": ')
  27. if adminMenu == '1':
  28. newUser()
  29. break
  30. elif adminMenu == '2':
  31. exit()
  32. break
  33.  
  34. def userMenu():
  35. print("User Menu")
  36. exit()
  37.  
  38. def newUser():
  39. userType, username, password1, password2 = "", "", "", ""
  40. while True:
  41.  
  42. userType = input('What type of user are you creating?\n(1) Admin\n(2) Defnyddiwr')
  43. if userType == '-1':
  44. mainMenu()
  45. if len(userType) > 1:
  46. print('\nInvalid Input!\n')
  47. elif userType.isdigit() != True:
  48. print('Please enter a number!')
  49. elif int(userType) <1:
  50. print('\nInvalid Input!\n')
  51. elif int(userType) >2:
  52. print('\nInvalid Input!\n')
  53. else:
  54. break
  55. while True:
  56. username = input('\n Please enter the username of the new user: ')
  57. if username == '-1':
  58. mainMenu()
  59. if len(username) >10:
  60. print('\nUsername must be less than 11 characters!\n')
  61. elif username.isalpha() == False:
  62. print('\nThe username must only contain alpha!\n')
  63. else:
  64. break
  65. while True:
  66. password1 = input('\nPlease enter the password for the user: ')
  67. if password1 == '-1':
  68. mainMenu()
  69. if len(password1) > 10:
  70. print('\nPassword must be less than 11 characters!\n')
  71. password2 = input('\nPlease enter the password again: ')
  72. if password2 == '-1':
  73. mainMenu()
  74. if len(password2) > 10:
  75. print('\nPassword must be less than 11 characters!\n')
  76. if password1 != password2:
  77. print('\nPasswords do not match!\n')
  78. else:
  79. break
  80.  
  81. username = username.lower()
  82. password1 = password1.lower()
  83. password2 = password2.lower()
  84.  
  85. userTypeStore = str(userType).ljust(1)
  86. usernameStore = username.ljust(10)
  87. passwordStore = password1.ljust(10)
  88.  
  89. store = open('users.txt','a')
  90. iStore = usernameStore + passwordStore + userTypeStore + "\n"
  91. store.write(iStore)
  92. store.close()
  93.  
  94. print('\nNew User Created: ')
  95. print('Usertype: ',userType)
  96. print('Username: ',username)
  97. print('Password: **********')
  98. mainMenu()
  99. def validateUser():
  100. validateUserType = ""
  101. validateUsername = ""
  102. validatePassword = ""
  103.  
  104. username = str(input('\nPlease enter your username: \n'))
  105. password = str(input('\nPlease enter your password: \n'))
  106.  
  107. while True:
  108. try:
  109. readUsers = open('users.txt','r')
  110. validateCounter = 0
  111.  
  112. while True:
  113. location = readUsers.readline()
  114. validateUserType = location[20:21]
  115. validateUsertype = validateUserType.strip()
  116.  
  117. validateUsername = location [0:10]
  118. validateUsername = validateUsername.strip()
  119. validateUsername = validateUsername.lower()
  120. username = username.lower()
  121.  
  122. validatePassword = location[10:20]
  123. validatePassword = validatePassword.strip()
  124. validatePassword = validatePassword.lower()
  125.  
  126. if location == "":
  127. readUsers.close()
  128. break
  129. if validateUserType == str(1) and validateUsername == username and validatePassword == password:
  130. validateCounter = validateCounter + 1
  131. adminMenu()
  132. break
  133. if validateUserType == str(2) and validateUsername == username and validatePassword == password:
  134. validateCounter = validateCounter + 1
  135. userMenu()
  136. break
  137.  
  138. if validateCounter ==0:
  139. print('\nNo user in the file with those login details. \n')
  140. validateUser()
  141. except FileNotFoundError:
  142. print('There is no Users file for you to search! How about making your first account?\nTop Tip, make it a System Administrator Account!\n')
  143. newUser()
  144. def main():
  145. mainMenu()
  146. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement