I am trying to code a login verificater where the username and passwords are stored into a separate text file, I am trying to get the text file to load up on Python and each separate word to be loaded onto separate variables.
For example, given the following text file:
admin, 1234
bigadmin, 5678
where admin
is the username and 1234
is the password, I want the same details loaded up onto Python but split up into two separate variables:
username = "admin"
password = "1234"
Here's the solution I'm currently using:
tempuserdatabase = open('user.txt')
userdatabase = tempuserdatabase.read().split(",")
username = input("Please enter your username:")
password = input("Please enter your password:")
if username == userdatabase[0] and password == userdatabase[1]:
print("successful")
else:
print("Please try again")
This was the initial code however this method has not been working. So while coding the rest of the code I figured out that is more convenient for the code to just be separated and stored into two different variables so that I can use it later on as well minimizing the amount of lines.