This a fairly basic script I made for use in some other projects, nothing too complex or sophisticated and obviously lacking in some features (Password/Username encryption, Missing file contingencies etc.).
It loads a text file (formatted as USERNAME, PASSWORD\nUSERNAME, PASSWORD\n
) into a 2D array, then checks the inputs against it, until 2 separate logins are used.
I'm what I'd consider intermediate in terms of python competency, but there are always things to be improved upon: any suggestions? I tend to use something similar to this for all projects that require a login, so any improvements or areas to look into, no matter how minor, would be greatly appreciated.
def login():
player_count, details = 0, [[data.strip() for data in line.split(",")] for line in open("username_password.txt", "r").read().splitlines()]
while player_count != 2:
username, password = input("USERNAME"), input("PASSWORD")
for data in details:
if username == data[0] and password == data[1]:
print("LOGIN CORRECT")
details.pop(details.index(data))
player_count += 1
break
else:
print("INCORRECT")
main()
def main():
print("LOGGED IN\nMAIN")
login()