Advertisement
Guest User

Untitled

a guest
May 8th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. class User:
  2.  
  3. def info_save(self, save_username_1, save_password_1):
  4. u_input = UserInput()
  5. if (save_password_1 and save_username_1) != "":
  6. file_read = open("user_list.txt")
  7. delimiter = ","
  8. data = {}
  9. for line in file_read.readlines():
  10. a = line.strip().split(delimiter)
  11. if len(a) == 2:
  12. data[a[0]] = a[1]
  13. file_read.close()
  14.  
  15. if save_username_1 in data:
  16. print("USERNAME is already in use", "\n")
  17. u_input.register()
  18. else:
  19. file_write = open("user_list.txt", "a")
  20. file_write.write(save_username_1 + "," + save_password_1 + "\n")
  21. file_write.close()
  22. print("your account has been saved", "\n")
  23. else:
  24. print("invalid USERNAME or PASSWORD", "\n")
  25. u_input.register()
  26.  
  27.  
  28. class Control:
  29.  
  30. def user_control(self, username_input, password_input, counter):
  31. u_input = UserInput()
  32. if counter != 0:
  33. if (username_input and password_input) != "":
  34. file = open("user_list.txt")
  35. delimiter = ","
  36. data = {}
  37. for line in file.readlines():
  38. a = line.strip().split(delimiter)
  39. if len(a) == 2:
  40. data[a[0]] = a[1]
  41. if username_input in data:
  42. password = data[username_input]
  43. if password == password_input:
  44. print("ACCESS")
  45. # add
  46. else:
  47. print("wrong password")
  48. print("you have", counter, "tries Left")
  49. counter -= 1
  50. u_input.login(i=counter)
  51. else:
  52. print("USERNAME ist not in existence please try to REGISTER", "\n")
  53. u_input.login(i=counter)
  54. else:
  55. print("invalid PASSWORD or USERNAME", "\n")
  56. u_input.login(i=counter)
  57. else:
  58. print("ACCESS DENIED")
  59.  
  60.  
  61. class UserInput:
  62.  
  63. def register(self):
  64. main_save = User()
  65. main_save.info_save(save_username_1=input("insert username: "),
  66. save_password_1=input("insert password: "))
  67.  
  68. def login(self, i):
  69.  
  70. main_control = Control()
  71. main_control.user_control(username_input=input("insert your username: "),
  72. password_input=input("insert your password: "),
  73. counter=i)
  74.  
  75.  
  76. class Main:
  77.  
  78. def start(self):
  79.  
  80. input_main = ""
  81.  
  82. reg = UserInput()
  83. input_main = input("type R for REGISTER or L for LOGIN: ")
  84. if input_main == "R" or input_main == "r":
  85. success_main = "true"
  86. print("\n")
  87. reg.register()
  88.  
  89. if input_main == "L" or input_main == "l":
  90. print("\n")
  91. reg.login(i=2)
  92.  
  93. else:
  94. entry = Main()
  95. entry.start()
  96.  
  97.  
  98. # entry point
  99. Entry = Main()
  100. Entry.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement