Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Register:
- def register_user(self, username_input, password_input):
- if (username_input and password_input) != "":
- file = open("user_list.txt")
- delimiter = ";"
- data = {}
- for line in file.readlines():
- a = line.strip().split(delimiter)
- if len(a) == 2:
- data[a[0]] = a[1]
- file.close()
- if username_input in data:
- save = 2
- else:
- file_write = open("user_list.txt", "a")
- file_write.write(username_input + "," + password_input + "\n")
- file_write.close()
- save = 1
- else:
- save = 3
- return save
- class Control:
- def user_control(self, username_input, password_input):
- if (username_input and password_input) != "":
- file = open("user_list.txt")
- delimiter = ";"
- data = {}
- for line in file.readlines():
- a = line.strip().split(delimiter)
- if len(a) == 2:
- data[a[0]] = a[1]
- if username_input in data:
- password = data[username_input]
- if password == password_input:
- access = 1
- else:
- access = 2
- else:
- access = 3
- else:
- access = 4
- return access
- class Input:
- def input_main_register(self):
- save_main = 0
- while save_main != 1:
- save_username = input("Insert Username: ")
- save_password = input("Insert Password: ")
- save_main = Register().register_user(username_input=save_username, password_input=save_password)
- if save_main == 2:
- print("USERNAME already in use")
- if save_main == 3:
- print("Invalid")
- if save_main == 1:
- print("succesfully saved")
- def input_main_login(self):
- try_main = 3
- access_main = 0
- while try_main != 0 and access_main != 1:
- control_username = input("USERNAME: ")
- control_password = input("PASSWORD: ")
- access_main = Control().user_control(username_input=control_username, password_input=control_password)
- if access_main == 2 or access_main == 3:
- try_main -= 1
- print("Wrong Parameter try again: ", "you have ", str(try_main), "tries left", "\n")
- if access_main == 3:
- print("try to register")
- if access_main == 4:
- print("Invalid")
- if access_main == 1:
- print("ACCESS")
- first_input = 0
- while first_input != 0 and first_input != 1:
- first_input = input("0 or 1")
- if first_input != 0 or first_input != 1:
- print("invalid")
- if first_input == 0:
- Input().input_main_register()
- if first_input == 1:
- Input().input_main_login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement