'read if name and password are in the same line in a txt file

I’m creating a login with registration where the data is saved in a txt file, and a login. but now if I login with name and password not matched, I still login.

in the txt file shows only username ( , ) and the password entered in the registration

this is the code:

    from tkinter import *
    import numpy as np
    import ast

    root = Tk()
    root.geometry("500x300")
    root.title("form")


    def signup():

      # verificare se un utente gia esiste

        registro_fatto.configure(text="Completata")

        file1 = open("provafile.txt", "a")
        file1.write(nome_utente_entry.get())
        file1.write(", ")
        file1.write(password_entry.get())
        file1.write("\n")
        file1.close()

        nome_utente_entry.delete(0, END)
        password_entry.delete(0, END)


    def signin():
        global nome_utente_entry
        global password_entry

        file = open('provafile.txt', 'r')
        file.readlines()
        file.close()

    if nome_utente_entry.get() and password_entry.get() in file:
        accesso_fatto.configure(text="accesso eseguito")
    elif nome_utente_entry.get() and password_entry.get() != file:
        accesso_fatto.configure(text="accesso negato")
    else:
        accesso_fatto.configure(text="Nome utente e password negato")

    nome_utente_entry.delete(0, END)
    password_entry.delete(0, END)



   #input nome utente
nome_utente = Label(root, text="Nome", font="Times 10 bold")
nome_utente.grid(row=1, column=1, padx=60)
nome_utente_entry = Entry(root)
nome_utente_entry.grid(row=1, column=2)

#input password
password = Label(root, text="Password", font="Times 10 bold")
password.grid(row=2, column=1)
password_entry = Entry(root, show="*")
password_entry.grid(row=2, column=2)

#bottone per accedere
accedi_button = Button(root, text="accedi", command=signin)
accedi_button.grid(row=3, column=1)
accedi_button.configure(cursor="hand2")
accesso_fatto = Label(root, text="", font="Times 10 bold")
accesso_fatto.grid(row=4, column=1)


#bottone per registrarsi
registrati_button = Button(root, text="registrati", command=signup)
registrati_button.grid(row=3, column=2)
registrati_button.configure(cursor="hand2")
registro_fatto = Label(root, text="", font="Times 10 bold")
registro_fatto.grid(row=4, column=2)


    if __name__ == '__main__':
        root.mainloop()

Please Can you tell me how to check if username and password are in the same line as the txt file?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source