How do I check a login with sqlite3 + Python3?

Asked

Viewed 720 times

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 can already do all buttons and database, now I want to know how to check the user login.

At login and requested Registration and Registration Number, all the information is already going to the database I created, I’m trying to find a way to authenticate the user who logs in, Only to be able to log in if the information is already in the database, if they are not refuse the login. I’m trying to find a way to do this, but I’m not getting it, can someone help me and give some tips ?

  • Can anyone answer ?

  • I edited and put all the code.

  • I don’t understand what your problem is. You just need to make a query matricula and numero de inscrição passing the value of the entries, if return other than None OK, if not incorrect login

  • As I’m running out of time to analyze your code and respond, follow a link that may be useful

  • Yes in this part I’m having problems, I’m not able to make it work, when I put the registration and the correct registration appears only ''Incorrect Login! If Voce has not yet registered, please register. '' I will see the link you send and try to fix the problem, thanks.

  • 1

    Already able to do, thanks for the information.

  • Israel, if possible answer the question with the solution to your problem, if someone has the same problem will already help ;)

Show 2 more comments
No answers

Browser other questions tagged

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