How do I check a login with sqlite3 + Python3?

1
from tkinter import *
from tkinter import messagebox
from random import randint
import os
import sqlite3
from tkinter import ttk

con = sqlite3.connect('BancoDeDadosCadastro.db')
cur = con.cursor()

cur.execute('CREATE TABLE IF NOT EXISTS BancoDeDadosCadastro (Nome VARCHAR, 
Turma VARCHAR, Turno VARCHAR, Matricula VARCHAR, Inscrição VARCHAR)')

root = Tk()
root.title('Cadastro Biblioteca Virtual')
root.geometry('700x500+0+0')
root.configure(background="green")
root.resizable(width=False, height=False)

'''Frame Topo'''
photo = PhotoImage(file = "topcadastro.png")
label = Label(root, image = photo)
label.pack(side=TOP)


'''Frame Direita'''
photo3 = PhotoImage(file = "side_right.png", width=480)
label3 = Label(root, image = photo3)
label3.pack(side=RIGHT)


lbl = Label(root, text="Cadastro / Login", bg="green", fg="white", font= 
("Century Gothic", 16, "bold"))
lbl.place(x=15, y=80)

def cad():
    clbl = Label(root, text="Cadastro para Biblioteca", font=("Century 
Gothic", 16, "bold"))
clbl.place(x=300, y=80)
clb2 = Label(root, text="Nome:", font=("Century Gothic", 10))
clb2.place(x=225, y=130)
centn = Entry(root, width=50)
centn.place(x=280, y=130)
clb3 = Label(root, text="Turma:", font=("Century Gothic", 10))
clb3.place(x=225, y=160)
cents = Entry(root, width=10)
cents.place(x=280, y=160)
clb4 = Label(root, text="Turno:", font=("Century Gothic", 10))
clb4.place(x=350, y=160)
centt = Entry(root, width=10)
centt.place(x=400, y=160)
clb5 = Label(root, text="Matrícula:", font=("Century Gothic", 10))
clb5.place(x=225, y=190)
centm = Entry(root, width=10)
centm.place(x=300, y=190)
albl = Label(root, text="Acesso para Biblioteca", font=("Century Gothic", 16, "bold"))
albl.place(x=300, y=270)
alb1 = Label(root, text="Matrícula:", font=("Century Gothic", 10))
alb1.place(x=225, y=325)
aentm = Entry(root, width=10)
aentm.place(x=300, y=325)
alb2 = Label(root, text="Nº da Inscrição:", font=("Century Gothic", 10))
alb2.place(x=370, y=325)
aentn = Entry(root, width=4)
aentn.place(x=480, y=325)

def shw():
    aentm['show'] = "●"
    aentn ["show"] = "●"
    avs = Label(root, text="O botao 'ⓘ' torna a senha oculta", font=("Century Gothic", 12))
    avs.place(x=225, y=450)
bts = Button(root, text="ⓘ", font=("Arial Black", 12), command=shw)
bts.place(x=520, y=320)

def cd():
    a = centn.get()
    b = cents.get()
    c = centt.get()
    d = centm.get()
    e = randint(0, 300)
    messagebox.showinfo(title="Confirmação", message=("Cadastrado \n Nº de Inscrição:" , e))
    messagebox.showinfo(title="Confirmação", message=("nome: ", a, "Turma: ", b, "Turno: ", c, "Matricula: ", d))
    print("nome: ", a, "Turma: ", b, "Turno: ", c, "Matricula: ", d, "Nº de Inscrição:" , e)
    centn.delete(0, 'end')
    cents.delete(0, 'end')
    centt.delete(0, 'end')
    centm.delete(0, 'end')
    cur.execute('INSERT INTO BancoDeDadosCadastro VALUES(?,?,?,?,?)',
            (a,b,c,d,e))
    con.commit()

cbt = Button(root, text="Cadastrar", font=("Arial", 13, "bold"), command=cd)
cbt.place(x=300, y=225)

def logar():
    x = aentm.get()
    y = aentn.get()
    try:
        cursor = cur.execute('SELECT Matricula AND Inscrição FROM BancoDeDadosCadastro')

        for row in cursor:
            if x in row:
                pas = cur.execute('SELECT Inscrição FROM BancoDeDadosCadastro WHERE Matricula')
                if y in pas:
                    messagebox.showinfo(title="Prosseguindo...", message=("Acesso Confirmado\n Bem Vindo"))
                    pas.fetclone()
                    os.startfile(r"GerenciadorLivros.py")
                else:
                    messagebox.showinfo(title="Prosseguindo...", message=("Senha Incorreta!"))

        messagebox.showinfo(title="Prosseguindo...", message=("Login Incorreto! Se voce ainda nao se registrou, favor registar."))
    finally:
        return

abt = Button(root, text="Acessar", font=("Arial", 13, "bold"), command=logar)
abt.place(x=300, y=375)

bt2 = Button(root, text="Cadastrar", font=("Arial", 13, "bold"), command=cad)
bt2.place(x=100, y=200)
bt = Button(root, text="Acessar", font=("Arial", 13, "bold"), command=cad)
bt.place(x=15, y=200)

photo4 = PhotoImage(file = "liceun.png")
label4 = Label(root, image = photo4)
label4.place(x=5, y=275)




root.mainloop()

Well I'm trying a registration system, I already get to do all the buttons and database, now I want to know how do I check the user login.

At login and requested Enrollment and Enrollment Number, all information is already going to the database that I created, I am trying to find a way to authenticate the user who is logged in, so that he can only log in if the information is already in the database, if they are not declining the login.  I'm trying to find a way to do this, but I can not, can someone help me and give some tips?

    
asked by anonymous 17.08.2018 / 16:31

0 answers