Advertisement
Guest User

Untitled

a guest
Mar 1st, 2019
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | None | 0 0
  1. import json
  2.  
  3. def add_account(username, password):
  4.     accounts[username] = password
  5.  
  6.  
  7. flag = True
  8. accounts = {}
  9. filename = 'accounts.json'
  10. with open(filename) as file_obj:
  11.     accounts = json.load(file_obj)
  12.  
  13.  
  14. while flag:
  15.  
  16.     print("\n( 1 ) - Criar Conta")
  17.     print("( 2 ) - Login")
  18.     print("( 3 ) - Eliminar Conta\n")
  19.  
  20.     choice = input("--> ")
  21.  
  22.     try:
  23.         choice = int(choice)
  24.     except ValueError:
  25.         print("You have to choose a number")
  26.     else:
  27.         if choice < 1 or choice > 3:
  28.             print("Write a number between 1-3")
  29.             continue
  30.         elif choice == 1:
  31.  
  32.             username = input("Username: ")
  33.             password = input("Password: ")
  34.  
  35.             while username in accounts.keys():
  36.                 print("That account is already registered!")
  37.                 username = input("Username: ")
  38.                 password = input("Password: ")
  39.  
  40.             add_account(username, password)
  41.             print("Account added!!")
  42.  
  43.         elif choice == 2:
  44.  
  45.             username = input("Username: ")
  46.             password = input("Password: ")
  47.  
  48.             while accounts[username] != password:
  49.                 print("Wrong login")
  50.                 username = input("Username: ")
  51.                 password = input("Password: ")
  52.             print("Logged in sucessfully!")
  53.  
  54.         elif choice == 3:
  55.             username = input("Username: ")
  56.             password = input("Password: ")
  57.  
  58.             while accounts[username] != password:
  59.                 print("Login incorreto")
  60.                 username = input("Username: ")
  61.                 password = input("Password: ")
  62.             accounts.pop(username)
  63.             print("Account deleted sucessfully!")
  64.  
  65.     with open(filename, 'w') as file_obj:
  66.         json.dump(accounts, file_obj)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement