vendredi 2 août 2019

why if statement does not compare the data in text file? python

I am trying to create a simple login system. The problem is, if statement is not executed at all even when I enter the correct username and password. this is my first time asking question. data from text file:

ted, teddy@gmail.com, 12345678
bean, bean@gmail.com, 12345678
with open('data.txt') as f:
    f_read = f.read().split()
    print(f_read)



n = str(input("Do you have an account?yes/no: "))

while n == "yes":
    username_check = input("enter a username: ")
    checkpass = input("enter your password: ")

    for line in open('data.txt','r').readlines():
        loginDetails = line.split()
        if username_check == loginDetails[0] and checkpass ==  loginDetails[2]:
           print("accepted")
           break
    else:
        print('not accepted')

this is the output.

Do you have an account?yes/no: yes
enter a username: bean
enter your password: 12345678
not accepted
enter a username:

Aucun commentaire:

Enregistrer un commentaire