Advertisement
Guest User

Untitled

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