My "user.txt" contains admin username and password(admin, admin). I use it to log in. Once I register a new user into the text file, the admin username and password don't work anymore, but I can log in using the new user credentials I have just created. Please help.
importing current date
from datetime import datetime
import csv
#opening user file
user_file = open("user.txt", "r+")
text = user_file.readlines()
login = False
#while login is false,
#if user enters correct credentials, login
#changes to True. Giving excess
while login == False:
username = input("Enter your username: ")
password = input("Enter your password: ")
for lines in text:
valid_user, valid_password = lines.split(", ")
valid_user, valid_password.strip()
if valid_user == username and valid_password == password:
login = True
print("Logging in...")
if valid_user != username and valid_password != password:
print("Invalid login details")
user_file.seek(0)
user_file.close()
source https://stackoverflow.com/questions/69728422/read-from-top-of-text-file-that-i-use-to-store-login-username-and-password
Comments
Post a Comment