I'm trying to create a login function which gains its validation from a json file. Im asking to see if theres a way that when the user enters their login_username it will check the json file to find the data for that specific person. The logic error i'm having right now is that the user can enter any login_username and login_password and it will be working. But the logic I want is that upon entering login_username it will go to the account detail of that username so I can match that username to that password.
main.py
def login():
login_username = input("Enter your username: ")
valid_username = False
login_password = input("Enter your password: ")
valid_password = False
#Username:
if login_username in username_list:
valid_username = True
print("Valid")
else:
print("Invalid username entered ")
username_tries = 0
while valid_username != True:
login_username = input("Re Enter your username: ")
username_tries = username_tries + 1
if login_username in username_list:
valid_username = True
print("Valid")
if username_tries == 5 and valid_username == False:
print("Username entered wrong too many times.")
exit()
#Password:
if login_password in password_list:
valid_password = True
print("Valid")
else:
print("Invalid password entered")
password_tries = 0
while valid_password != True:
login_password = input("Re Enter your password: ")
password_tries = password_tries + 1
if login_password in password_list:
valid_password = True
print("Valid")
if password_tries == 5 and valid_password == False:
print("Username entered wrong too many times.")
exit()
#Confirmation:
if (valid_username == True) and (valid_password == True):
print("Granted Access!")
print(f"Welcome {login_username}! ")
accounts.json
{
"account_details": [
{
"Username": "testing1892437",
"Password": "testing123",
"Email": "testing1239807@gmail.com",
"Token": "EZEEPO5A4Y"
},
{
"Username": "iasodlfj123",
"Password": "amandsf",
"Email": "ammaisdlkjufghbaf@gmail.com",
"Token": "CAFI7NEUR4"
}
]
}