I'm trying to create a task manager program (in Python) that allows a user to login and view/add tasks. The user logins are stored in text file called user.txt. I'm struggling to validate the username and password so that they can login and access the menu of the task manager.
Disclaimer: I'm still a beginner.
This is what I've tried so far:
usernames = []
passwords = []
with open("user.txt", "r") as f1:
for lines in f1:
logins = lines.strip()
logins = lines.split(",")
username = logins[0]
password = logins[1]
usernames.append(logins[0])
passwords.append(logins[1])
user_name = input("Please enter your username:\n")
pass_word = input("Please enter your password:\n")
if user_name == username and pass_word == password:
menu = input('''Please select one of the following options:\n
r - register a user
a - add task
va - view all tasks
vm - view my tasks
e - exit ''').lower()
This is the contents of the user.txt file:
admin, adm1n
When I entered the username and password from the user.txt file, I expected it to print the menu but that didn't happen.
passwordhas a leading space. One way to fix it is to change:to:
When I run the code and enter
adminandadm1n, I see the menu printed out.Since you are a beginner, the simplest way to debug your code is to
printvariable values. I did this to see thatpasswordhas a leading space.