Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- def add_account(username, password):
- accounts[username] = password
- flag = True
- accounts = {}
- filename = 'accounts.json'
- with open(filename) as file_obj:
- accounts = json.load(file_obj)
- while flag:
- print("\n( 1 ) - Criar Conta")
- print("( 2 ) - Login")
- print("( 3 ) - Eliminar Conta\n")
- choice = input("--> ")
- try:
- choice = int(choice)
- except ValueError:
- print("You have to choose a number")
- else:
- if choice < 1 or choice > 3:
- print("Write a number between 1-3")
- continue
- elif choice == 1:
- username = input("Username: ")
- password = input("Password: ")
- while username in accounts.keys():
- print("That account is already registered!")
- username = input("Username: ")
- password = input("Password: ")
- add_account(username, password)
- print("Account added!!")
- elif choice == 2:
- username = input("Username: ")
- password = input("Password: ")
- while accounts[username] != password:
- print("Wrong login")
- username = input("Username: ")
- password = input("Password: ")
- print("Logged in sucessfully!")
- elif choice == 3:
- username = input("Username: ")
- password = input("Password: ")
- while accounts[username] != password:
- print("Login incorreto")
- username = input("Username: ")
- password = input("Password: ")
- accounts.pop(username)
- print("Account deleted sucessfully!")
- with open(filename, 'w') as file_obj:
- json.dump(accounts, file_obj)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement