Advertisement
Guest User

Untitled

a guest
May 14th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.39 KB | None | 0 0
  1. class Register:
  2.  
  3.     def register_user(self, username_input, password_input,this_list):
  4.  
  5.         if (username_input and password_input) != "":
  6.             file_read = open(this_list)
  7.             delimiter = ";"
  8.             data1 = {}
  9.             for line in file_read.readlines():
  10.                 a = line.strip().split(delimiter)
  11.                 if len(a) == 2:
  12.                     data1[a[0]] = a[1]
  13.                     file_read.close()
  14.  
  15.             if username_input in data1:
  16.                 save = 2
  17.  
  18.             else:
  19.                 file_write = open("user_list.txt", "a")
  20.                 file_write.write(username_input + ";" + password_input + "\n")
  21.                 file_write.close()
  22.                 save = 1
  23.                 print(username_input)
  24.                 print(str(data1))
  25.  
  26.         else:
  27.             save = 3
  28.         return save
  29.  
  30.  
  31. class Control:
  32.  
  33.     def user_control(self, username_input, password_input, this_list):
  34.  
  35.         if (username_input and password_input) != "":
  36.             file = open(this_list)
  37.             delimiter = ";"
  38.             data = {}
  39.             for line in file.readlines():
  40.                 a = line.strip().split(delimiter)
  41.                 if len(a) == 2:
  42.                     data[a[0]] = a[1]
  43.  
  44.             if username_input in data:
  45.                 password = data[username_input]
  46.                 if password == password_input:
  47.                     access = 1
  48.                 else:
  49.                     access = 2
  50.             else:
  51.                 access = 3
  52.         else:
  53.             access = 4
  54.         return access
  55.  
  56.  
  57. class Input:
  58.  
  59.     def input_main_register(self, second_list):
  60.  
  61.         save_main = 0
  62.         while save_main != 1:
  63.             save_username = input("Insert Username: ")
  64.             save_password = input("Insert Password: ")
  65.             save_main = Register().register_user(username_input=save_username, password_input=save_password,
  66.                                                  this_list=second_list)
  67.             if save_main == 2:
  68.                 print("USERNAME already in use")
  69.             if save_main == 3:
  70.                 print("Invalid")
  71.         if save_main == 1:
  72.             print("succesfully saved")
  73.  
  74.     def input_main_login(self, second_list):
  75.  
  76.         try_main = 3
  77.         access_main = 0
  78.  
  79.         while try_main != 0 and access_main != 1:
  80.             control_username = input("USERNAME: ")
  81.             control_password = input("PASSWORD: ")
  82.             access_main = Control().user_control(username_input=control_username, password_input=control_password,
  83.                                                  this_list=second_list)
  84.  
  85.             if access_main == 2 or access_main == 3:
  86.                 try_main -= 1
  87.                 print("Wrong Parameter try again: ", "you have ", str(try_main), "tries left", "\n")
  88.  
  89.             if access_main == 3:
  90.                 print("try to register")
  91.  
  92.             if access_main == 4:
  93.                 print("Invalid")
  94.         if access_main == 1:
  95.             print("ACCESS")
  96.  
  97.  
  98. first_list = "user_list.txt"
  99. first_input = ""
  100. while first_input != "r" and first_input != "l":
  101.     first_input = input("r or l")
  102.     if first_input != "l" or first_input != "r":
  103.         print("invalid")
  104.  
  105. if first_input == "r":
  106.     Input().input_main_register(second_list=first_list)
  107. if first_input == "l":
  108.     Input().input_main_login(second_list=first_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement