[Python] How to check the username in text file or not and then ask for the password?

Discussão em 'Python' iniciado por Stack, Junho 11, 2025.

  1. Stack

    Stack Membro Participativo

    loginUsername = input("Enter Username: ")
    loginPassword = input("Enter PASSWORD: ")

    data=open('database.txt', 'r')
    accounts = data.readlines()

    for line in data:
    accounts = line.split(",")
    if (loginUsername == accounts[0] and loginPassword == accounts[1]):
    print("LOGGED IN")
    else:
    print("Login FAILED")

    print(accounts)


    I want to make a text login system, which will ask for the username first. After checking the text file which stored username and password, the system will ask for password. But I don't know how to read the first column (which is username, the structure of the text file is "username, password"). If i use readlines() and split(","). But there is "n" at the end of the password.

    Continue reading...

Compartilhe esta Página