So I am basically trying to make a login system where the usernames and their passwords should be stored somewhere permanently. I tried importing my dictionary into a json file but that doesn’t work if the runtime is disconnected.
This is what I have coded:
import json
import getpass
with open('Users.json') as f:
Users = json.load(f)
with open('Completed.json') as f:
Complete = json.load(f)
Q_Bank = {}
def clear():
from IPython.display import clear_output
clear_output()
print(' SIGN IN')
Username = input('Username: ')
if Username in Users.keys():
Password = getpass.getpass(prompt='Enter your password: ')
while Users[Username]['Password'] != Password:
print('Wrong Password!')
Password = getpass.getpass(prompt='Enter your password: ')
else:
clear()
print('Welcome back ' + Username + '!')
else:
print('Your username does not seem to exist. Please create a new one.')
print(' LOG IN')
Username = input('Username: ')
Password = getpass.getpass(prompt='Enter your password: ')
clear()
print('Hello ' + Username + '!')
User = {
'Password' : Password
}
Users[Username] = User
with open('Users.json', 'w') as f:
json.dump(Users, f)
New contributor
Raisel Raja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.