daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Jan 17th, 2019 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. def mainMenu():
  4.     print("""
  5. ###############################################################################
  6. #                                                                             #
  7. #                            Clive's Carpets                                  #
  8. #                          Please Login Below!                                #
  9. #                                                                             #
  10. ###############################################################################
  11. """)
  12.     validateUser()
  13.    
  14. def adminMenu():
  15.     while True:
  16.         print("""
  17. ###############################################################################
  18. #                                                                             #
  19. #                            Clive's Carpets                                  #
  20. #                               Admin Menu                                    #
  21. #                                                                             #
  22. # 1 - Add a New User                                                          #
  23. # 2 - Exit                                                                    #
  24. #                                                                             #
  25. ###############################################################################
  26. """)
  27.  
  28.         adminMenu = input("Which option would you like to choose? '1' or '2': ")
  29.         if adminMenu == "1":
  30.             newUser()
  31.             break
  32.         elif adminMenu == "2":
  33.             exit()
  34.             break
  35.    
  36.  
  37. def userMenu():
  38.     print("User Menu")
  39.     exit()
  40.    
  41.  
  42. def newUser():
  43.     userType, username, password1, password2 = "", "", "", ""
  44.     while True:
  45.        
  46.         userType = input("What type of user are you creating?\n(1) Admin \n(2) Defnyddiwr \n")
  47.         if userType == "-1":
  48.             mainMenu()
  49.         if len(userType) > 1:
  50.             print("\nInvalid Input.\n")
  51.         elif userType.isdigit() != True:
  52.             print("Please enter a number!")
  53.         elif int(userType) <1:
  54.             print("\nInvalid Input.\n")
  55.         elif int(userType) >2:
  56.             print("\nInvalid Input.\n")
  57.         else:
  58.             break
  59.     while True:
  60.         username = input("\nPlease enter the username of the new user: ")
  61.         if username == "-1":
  62.             mainMenu()
  63.         if len(username) >10:
  64.             print("\nUsername must be less than 11 characters.\n")
  65.         elif username.isalpha() == False:
  66.             print("\nThe username must only contain alpha.\n")
  67.         else:
  68.             break
  69.     while True:
  70.         password1 = input("\nPlease enter the password for the user: ")
  71.         if password1 == "-1":
  72.             mainMenu()
  73.         if len(password1) > 10:
  74.             print("\nPassword must be less than 11 characters.\n")
  75.         password2 = input("\nPlease enter the password again: ")
  76.         if password2 == "-1":
  77.             mainMenu()
  78.         if len(password2) > 10:
  79.             print("\nPassword must be less than 11 characters.\n")
  80.         if password1 != password2:
  81.             print("\nPasswords do not match.\n")
  82.         else:
  83.             break
  84.     while True:
  85.         FirstName = input("\nPlease enter your first name: ")
  86.         if FirstName == "-1":
  87.             mainMenu()
  88.         if len(FirstName) >25:
  89.             print("\n First name must be less than 25 characters.\n")
  90.         else:
  91.             break
  92.     while True:
  93.         Surname = input("\nPlease enter your surname: ")
  94.         if Surname == "-1":
  95.             mainMenu()
  96.         if len(Surname) >25:
  97.             print("\nSurname must be less than 25 characters.\n")
  98.         else:
  99.             break
  100.     while True:
  101.         Telephone = input("\nPlease enter your telephone: ")
  102.         try:
  103.             int(Telephone)
  104.         except:
  105.             print("Telephone number must be a number")
  106.         if Telephone == "-1":
  107.             mainMenu()
  108.         if len(Telephone) >16:
  109.             print("\nTelephone must be less than 16 characters.\n")
  110.         else:
  111.             break
  112.     while True:
  113.         Town = input("\nPlease enter your postcode: ")
  114.         if Town == "-1":
  115.             mainMenu()
  116.         if len(Town) >250:
  117.             print("\nPostcode must be less than 250 characters.\n")
  118.         else:
  119.             break
  120.        
  121.        
  122.        
  123.     username = username.lower()
  124.     password1 = password1.lower()
  125.     password2 = password2.lower()
  126.     FirstName = FirstName.lower()
  127.     Surname = Surname.lower()
  128.     Telephone = Telephone.lower()
  129.     Town = Town.lower()
  130.      
  131.     userTypeStore = str(userType).ljust(2)
  132.     usernameStore = username.ljust(10)
  133.     passwordStore = password1.ljust(10)
  134.     FirstNameStore = FirstName.ljust(25)
  135.     SurnameStore = Surname.ljust(25)
  136.     TelephoneStore = Telephone.ljust(16)
  137.     TownStore = Town.ljust(8)
  138.  
  139.     store = open("users.txt","a")
  140.     iStore = usernameStore + passwordStore + userTypeStore + FirstNameStore + SurnameStore + TelephoneStore + PostcodeStore + "\n"
  141.     store.write(iStore)
  142.     store.close()
  143.  
  144.     print("\nNew User Created: ")
  145.     print("Usertype: ",userType)
  146.     print("Username: ",username)
  147.     print("Password: ",("*"*len(password1)))
  148.     print("First Name: ",FirstName)
  149.     print("Surname: ",Surname)
  150.     print("Telephone: ",Telephone)
  151.     print("Town: ",Town)
  152.     mainMenu()
  153.  
  154.  
  155. def validateUser():
  156.     validateUserType = ""
  157.     validateUsername = ""
  158.     validatePassword = ""
  159.  
  160.     username = str(input("\nPlease enter your username: \n"))
  161.     password = str(input("\nPlease enter your password: \n"))
  162.  
  163.     while True:
  164.         try:
  165.             readUsers = open("users.txt","r")
  166.             validateCounter = 0
  167.  
  168.             while True:
  169.                 location = readUsers.readline()
  170.                 validateUserType = location[20:22]
  171.                 validateUsertype = validateUserType.strip()
  172.  
  173.                 validateUsername = location [0:10]
  174.                 validateUsername = validateUsername.strip()
  175.                 validateUsername = validateUsername.lower()
  176.                 username = username.lower()
  177.  
  178.                 validatePassword = location[10:20]
  179.                 validatePassword = validatePassword.strip()
  180.                 validatePassword = validatePassword.lower()
  181.  
  182.                
  183.  
  184.                 if location == "":
  185.                     readUsers.close()
  186.                     break
  187.                 if validateUserType == str(1) and validateUsername == username and validatePassword == password:
  188.                     validateCounter = validateCounter + 1
  189.                     adminMenu()
  190.                     break
  191.                 if validateUserType == str(2) and validateUsername == username and validatePassword == password:
  192.                     validateCounter = validateCounter + 1
  193.                     userMenu()
  194.                     break
  195.  
  196.             if validateCounter ==0:
  197.                 print("\nNo user in the file with those login details. \n")
  198.                 validateUser()
  199.         except FileNotFoundError:
  200.             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")
  201.             newUser()
  202.  
  203. def main():
  204.     mainMenu()
  205. main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top