How to Validate User Input within a . txt file

Asked

Viewed 70 times

0

I have a registration program that receives the user’s data (e-mail and password), this data goes to a file . txt, with the function Open() python, example:

txt file

[email protected], senha1234
[email protected], 12345678

First the user’s email is written then comes a "," to separate the email from the password.

After the user registers he needs to log in. Here’s the problem, how can I do to check inside the file .txt if the password the user entered in the login matches his email address?

Code

import PySimpleGUI as sg

def Login():

sg.theme('Black')
layout = [
    [sg.Text('E-mail'), sg.Input(size=(25,5), key='email')],
    [sg.Text('Senha'), sg.Input(size=(25,0), key='Pass')],
    [sg.Button('Log-in')]
]

#  Gerar Janela
janela = sg.Window('Log-in', layout)
button, values = janela.Read()

#  Armazenando valores
email = values['email']
Pass = values['Pass']


#  Condicionais
if '@gmail.com' not in email[-10:]:
    pass


elif len(Pass) < 8:
    print('Senha deve conter 8 ou mais caracteres')


else:

    with open(r'Works\Log-in\obb\bcdds.txt', 'r', encoding='utf-8') as file:
        dados = file.read()

        if email not in dados:
            print('E-mail não cadastrado.')

        elif Pass:
            **Aqui vem a checagem para saber se a senha corresponde ao email**

1 answer

0


Make a recursion on each record of the file and compare the email as soon as you find the corresponding email compare the password type and if it is true do something.

Pseudo code example:

    for line in dado:
         eml,password = line.split(",")

         if eml == email and senha == password:
           #Do Stufff

Browser other questions tagged

You are not signed in. Login or sign up in order to post.