Guest User

Untitled

a guest
Jan 28th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. import json
  2. print ('1.Login')
  3. print ('2.Register')
  4. print('3.Exit')
  5.  
  6. def disp():
  7. while True:
  8.  
  9. check = int(input('enter your choice 1/2/3:'))
  10.  
  11. if check == 1:
  12. Login()
  13. elif check == 2:
  14. Register()
  15. elif check == 3:
  16. print('You are successfully exit!')
  17. break
  18.  
  19. print('*'*50)
  20.  
  21. def Register():
  22.  
  23.  
  24. username = input('create username:')
  25. userid = input('create userid:')
  26. password = input('enter you password:')
  27. users = {}
  28.  
  29. users[userid] = []
  30. users[userid].append({
  31. 'username': username,
  32. 'userid': userid,
  33. 'password': password
  34. })
  35. with open('users1.txt') as json_file:
  36. user = json.load(json_file)
  37. user.update(users)
  38.  
  39. with open('users1.txt', 'w') as outfile:
  40. json.dump(user, outfile)
  41. print('user created')
  42. print('*' * 50)
  43.  
  44.  
  45.  
  46.  
  47. def Login():
  48.  
  49. username = input('enter user login name:')
  50.  
  51. userid = input('create userid:')
  52. password = input('enter password:')
  53. try:
  54. with open('users1.txt') as json_file:
  55. users = json.load(json_file)
  56. for p in users[userid]:
  57. a = p['username']
  58. b = p['userid']
  59. c = p['password']
  60.  
  61. if a and b and c == username and password and userid:
  62. print('login successfully')
  63.  
  64. print('1.Add user')
  65. print('2. List of users')
  66. print('3. Logout')
  67.  
  68. except KeyError:
  69. print("login failed! please provide correct username and password")
  70. print ('1.Login')
  71. print ('2.Register')
  72. print('3.Exit')
  73.  
  74. disp()
  75.  
  76. while True:
  77. chk = int(input('enter your choice 1/2/3:'))
  78.  
  79. if chk == 1:
  80. after_login()
  81. elif chk == 2:
  82. list_of_users()
  83. elif chk == 3:
  84. print('You are successfully exit!')
  85. exit()
  86.  
  87. print('*' * 50)
  88.  
  89.  
  90. def after_login():
  91. d = {}
  92. Userlogin = input('create username:')
  93. Userid = input('create userid:')
  94. Userpassword = input('enter you password:')
  95. d['details'] = []
  96. d['details'].append({
  97. 'Userlogin': Userlogin,
  98. 'Userid': Userid,
  99. 'Userpassword': Userpassword
  100. })
  101.  
  102.  
  103. with open('users2.txt', 'w') as outfile:
  104. json.dump(d, outfile)
  105. print('user profile created')
  106. print('*' * 50)
  107.  
  108. def list_of_users():
  109. with open('users2.txt') as json_file:
  110. d = json.load(json_file)
  111. for p in d['details']:
  112. print('Userlogin: ' + p['Userlogin'])
  113. print('Userid: ' + p['Userid'])
  114. print('Userpassword: ' + p['Userpassword'])
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. disp()
Add Comment
Please, Sign In to add comment