Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.71 KB | None | 0 0
  1. def CreateUser():
  2.     username, password1, password2 = "", "", "", ""
  3.     while True:
  4.         username = input("\nPlease enter the username of the new user: ")
  5.         if username == "-1":
  6.             mainMenu()
  7.         if len(username) >10:
  8.             print("\nUsername must be less than 11 characters.\n")
  9.         elif username.isalpha() == False:
  10.             print("\nThe username must only contain alpha.\n")
  11.         else:
  12.             break
  13.     while True:
  14.         password1 = input("\nPlease enter the password for the user: ")
  15.         if password1 == "-1":
  16.             mainMenu()
  17.         if len(password1) > 10:
  18.             print("\nPassword must be less than 11 characters.\n")
  19.         password2 = input("\nPlease enter the password again: ")
  20.         if password2 == "-1":
  21.             mainMenu()
  22.         if len(password2) > 10:
  23.             print("\nPassword must be less than 11 characters.\n")
  24.         if password1 != password2:
  25.             print("\nPasswords do not match.\n")
  26.         else:
  27.             break
  28.         username = username.lower()
  29.         password1 = password1.lower()
  30.         password2 = password2.lower()
  31.  
  32.         usernameStore = username.ljust(10)
  33.         passwordStore = password1.ljust(10)
  34.  
  35.         f = open("users.txt","a")
  36.         iStore = usernameStore + passwordStore + "\n"
  37.         f.write(iStore)
  38.         f.close()
  39.  
  40.     print("\nNew User Created: ")
  41.  
  42. def CreateFiles():
  43.     f = open("users.txt","w+")
  44.     print("user file created")
  45.     f = open("passwords.txt","w+")
  46.     print("password file created")
  47.     f = open("customerID.txt","w+")
  48.     print("customerID file created")
  49.     f = open("stockID.txt","w+")
  50.     print("stockID file created")
  51.     f = open("customerID.txt","w+")
  52.     print("customerID file created")
  53.     f = open("customerID.txt","w+")
  54.     print("customerID file created")
  55.     f = open("invoiceID.txt","w+")
  56.     print("invoiceID file created")      
  57. CreateFiles()
  58.  
  59. def ValidateUserType():
  60.     validateUserType = ""
  61.     validateUsername = ""
  62.     validatePassword = ""
  63.  
  64.     username = str(input("\nPlease enter your username: \n"))
  65.     password = str(input("\nPlease enter your password: \n"))
  66.  
  67.     while True:
  68.         try:
  69.             f = open("users.txt","r")
  70.             validateCounter = 0
  71.  
  72.             while True:
  73.                 location = f.readline()
  74.                 validateUserType = location[20:22]
  75.                 validateUserType = validateUserType.strip()
  76.  
  77.                 validateUsername = location [0:10]
  78.                 validateUsername = validateUsername.strip()
  79.                 validateUsername = validateUsername.lower()
  80.                 username = username.lower()
  81.  
  82.                 validatePassword = location[10:20]
  83.                 validatePassword = validatePassword.strip()
  84.                 validatePassword = validatePassword.lower()
  85.                 password = password.lower()
  86.  
  87.                 if location == "":
  88.                     f.close()
  89.                     break
  90.                 if validateUserType == str(1) and validateUsername == username and validatePassword == password:
  91.                     validateCounter = validateCounter + 1
  92.                     adminMenu()
  93.                     break
  94.                 if validateUserType == str(2) and validateUsername == username and validatePassword == password:
  95.                     validateCounter = validateCounter + 1
  96.                     userMenu()
  97.                     break
  98.  
  99.             if validateCounter ==0:
  100.                 print("\nNo user in the file with those login details. \n")
  101.                 ValidateUserType()
  102.         except FileNotFoundError:
  103.             print("There is no Users file for you to search!\n")
  104.             CreateUser()
  105. ValidateUserType()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement