I am making a login script for python and it will create passwords and write them to a text file like (username:password). But I want to add a login script that will check to see if the username and password is in the text file.
def reg():
print('Creating new text file')
name = input('Username: ')
passwrd = input('Password: ')
with open("users.txt", "r+") as f:
old = f.read()
f.seek(0)
f.write(name + ":" + passwrd + "\n" + old)
f.close()
def login():
user = input("username: ")
passwrd = input("password: ")
with open('users.txt') as f:
credentials = [x.strip().split(':') for x in f.readlines()]
for user,passwrd in credentials:
(This is where i want to add the code)
reg()
login()
I think it would be something like.
for user,passwrd in credentials:
print("found")
else:
print("not found")
for user,passwrdtoif [user,passwrd]if you want to check whether the inputs are in credentials list