Guest User

Untitled

a guest
Sep 2nd, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. import json
  2.  
  3. filename = "users.json"
  4. with open(filename, "r+", encoding='utf8') as file:
  5. '''opens json file and separates it by line by storing each line into an
  6. array'''
  7. lines = file.readlines()
  8.  
  9. login_info = {}
  10. '''array that will store usernames and passwords for each user(each line in
  11. the file is a user)'''
  12.  
  13. for line in lines:
  14. '''simply prints each element of the lines array displaying the
  15. information of each user'''
  16. info = json.loads(line)
  17. print("USER: " + str(info))
  18. print("username: " + info["username"])
  19. print("password: " + info["password"] + "n")
  20. login_info[info["username"]] = info["password"]
  21. '''creates a new pair of username and password for each user(each line is
  22. a user)'''
  23. print(login_info)
  24.  
  25.  
  26. print(lines)
  27. print(login_info)
  28.  
  29. '''prompts user for their username and password'''
  30. prompt_username = input("Please enter username: ")
  31. prompt_password = input("Please input password: ")
  32.  
  33. def login(username, password):
  34. '''if username exists and the inputed strings match one of the key-value
  35. pairs, login is successful'''
  36.  
  37. if username in login_info:
  38. if password == info["password"]:
  39. print("LOGIN SUCCESSFUL")
  40. else:
  41. print("Sorry, password does not exist.")
  42. else:
  43. print("Sorry this username or password does not exist.")
  44.  
  45. login(prompt_username, prompt_password)
Add Comment
Please, Sign In to add comment