Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. {
  2. "users": [
  3. {
  4. "password": "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918",
  5. "username": "Admin"
  6. }
  7. ]
  8. }
  9.  
  10. json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
  11.  
  12. with open('userProfiles.json', 'r+') as f: #Open up the json file for reading/writing.
  13. data = f.read()
  14. print(data) # Debug message to check if f.read actually contains anything...
  15. currentProfiles = json.loads(data) # Load the json into a useable list.
  16. print(currentProfiles) # Debug Message: So I can check if the list loads properly
  17. username = input("Enter username: ")
  18. password = hashlib.sha256((input("Enter Password: ")).encode('utf-8')).hexdigest() # Create an sha256 hash to be used later to authenticate users.
  19. newUser = json.dumps({'users':[{'username':username, 'password':password}]}, sort_keys=True, indent=4)
  20. f.write(newUser)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement