I'm looking at creating a very basic username and password program using an external CSV file. The program allows the user to input a username and password, afterwards an if statement checks whether the username and password match that of a row in the CSV document. If so then the corresponding user information is displayed.
The issue I'm having is to with my else: statement. If the user details don't match that of a row (wrong username or password) a notification should display. By adding an else line though, it checks per line so I receive more than one "Details entered incorrectly." messages. Also if the credentials are correct, the user information is displayed alongside "Details entered incorrectly" for every other row.
import csv
Username = input("Username: ")
Password = input("Password: ")
with open('data.csv', 'rt', newline='') as file:
open_file = csv.reader(file)
for row in open_file:
if row[0] == Username and row[1] == Password:
print("Secret phrase: ", row[2])
else:
print("Incorrect user details.")
Any ideas on how I could alter my code to fix this? Much appreciated!