Advertisement
Guest User

Untitled

a guest
May 10th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. class Register:
  2.  
  3. def register_user(self, username_input, password_input):
  4.  
  5. if (username_input and password_input) != "":
  6. file_read = open("user_list.txt")
  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):
  34.  
  35. if (username_input and password_input) != "":
  36. file = open("user_list.txt")
  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):
  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. if save_main == 2:
  67. print("USERNAME already in use")
  68. if save_main == 3:
  69. print("Invalid")
  70. if save_main == 1:
  71. print("succesfully saved")
  72.  
  73.  
  74.  
  75. def input_main_login(self):
  76.  
  77. try_main = 3
  78. access_main = 0
  79.  
  80. while try_main != 0 and access_main != 1:
  81. control_username = input("USERNAME: ")
  82. control_password = input("PASSWORD: ")
  83. access_main = Control().user_control(username_input=control_username, password_input=control_password)
  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. first_input = ""
  98. while first_input != "r" and first_input != "l":
  99. first_input = input("r or l")
  100. if first_input != "l" or first_input != "r":
  101. print("invalid1")
  102.  
  103. if first_input == "r":
  104. Input().input_main_register()
  105. if first_input == "l":
  106. Input().input_main_login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement