Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- admin = False
- def firstMenu():
- print("Pick an option")
- menu = [
- "Login",
- "New User",
- "List of users"
- ]
- for n in range(len(menu)):
- print("{} {}".format(n+1, menu[n]))
- given = int(input())
- if given == 1:
- login()
- elif given == 2:
- addAccount()
- elif given == 3:
- listAccounts()
- else:
- print("sorry didn't understand")
- def login():
- username = input("username: ")
- password = input("password: ")
- if authenticate(username,password):
- print("you exist")
- main()
- else:
- print ("Sorry, no account matches: Make an account!")
- addAccount()
- def userFileExists(username):
- print()
- def listAccounts():
- accounts =loadAccount()
- for account in accounts:
- print ("{username}".format(**account))
- main()
- def authenticate(whichName,theirPassword):
- theUsers = loadAccount()
- for person in theUsers:
- if (person['username']== whichName):
- if (person['password'] == theirPassword):
- return True
- def loadAccount():
- with open('users.json') as f:
- theUsers = json.loads(f.read())
- return theUsers
- def addAccount():
- stuff = {}
- stuff['username'] = input("username: ")
- stuff['password'] = input("password: ")
- original = loadAccount()
- original.append(stuff)
- with open('users.json','w')as f:
- f.write(json.dumps(original))
- main()
- def main():
- firstMenu()
- main()
Add Comment
Please, Sign In to add comment