Guest User

Untitled

a guest
Nov 28th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import json
  2.  
  3. admin = False
  4.  
  5. def firstMenu():
  6. print("Pick an option")
  7. menu = [
  8. "Login",
  9. "New User",
  10. "List of users"
  11. ]
  12.  
  13. for n in range(len(menu)):
  14. print("{} {}".format(n+1, menu[n]))
  15.  
  16. given = int(input())
  17.  
  18. if given == 1:
  19. login()
  20. elif given == 2:
  21. addAccount()
  22. elif given == 3:
  23. listAccounts()
  24. else:
  25. print("sorry didn't understand")
  26.  
  27. def login():
  28. username = input("username: ")
  29. password = input("password: ")
  30. if authenticate(username,password):
  31. print("you exist")
  32. main()
  33. else:
  34. print ("Sorry, no account matches: Make an account!")
  35. addAccount()
  36.  
  37. def userFileExists(username):
  38. print()
  39.  
  40. def listAccounts():
  41. accounts =loadAccount()
  42. for account in accounts:
  43. print ("{username}".format(**account))
  44. main()
  45.  
  46. def authenticate(whichName,theirPassword):
  47. theUsers = loadAccount()
  48. for person in theUsers:
  49. if (person['username']== whichName):
  50. if (person['password'] == theirPassword):
  51. return True
  52.  
  53. def loadAccount():
  54. with open('users.json') as f:
  55. theUsers = json.loads(f.read())
  56. return theUsers
  57.  
  58. def addAccount():
  59. stuff = {}
  60. stuff['username'] = input("username: ")
  61. stuff['password'] = input("password: ")
  62. original = loadAccount()
  63. original.append(stuff)
  64. with open('users.json','w')as f:
  65. f.write(json.dumps(original))
  66. main()
  67.  
  68. def main():
  69. firstMenu()
  70.  
  71. main()
Add Comment
Please, Sign In to add comment