0
I am creating a simple login system, where the user puts the data entered in a table. But in the code when comparing the data, either it ENTERS even with blank spaces or wrong information or it accuses as incorrect any kind of attempt, even correct.
Follow the function of creating the table:
def createTableusers(self):
c = self.conn.cursor()
c.execute('''
CREATE TABLE IF NOT EXISTS usuarios(
user varchar(20))''')
self.conn.commit()
c.close()
Follows the class and insert function:
class Users(object):
def __init__(self, nome = '', senha = '', operador = '', entrada = '', saida = '', creditos = '',):
self.info = {}
self.nome = nome
self.senha = senha
self.operador = operador
self.entrada = entrada
self.saida = saida
self.creditos = creditos
def insertOperador(self, operador, senha):
try:
bank = Bank()
c = bank.conn.cursor()
c.execute('''Insert into operadores(operador, senha)
values (?, ?)
''', (operador, senha))
bank.conn.commit()
c.close()
return "Operador cadastrado com sucesso!"
except:
return 'Erro na cadastro do operador'
Follow the SELECT function:
def selectOperador(self,operador,senha):
bank = Bank()
try:
c = bank.conn.cursor()
c.execute('''SELECT * FROM operadores
WHERE operador = ? AND senha = ?
''', (operador, senha))
ver = c.fetchall()
if (operador in ver and senha in ver):
return 'Operador conectado'
except:
return 'Ocorreu um erro na busca!'
Login function:
def login(self):
u = Users()
operador = txt_usuario.text()
senha = txt_senha.text()
entrar = u.selectOperador(operador,senha)
if entrar == 'Operador conectado':
print('VDC')
else:
msg = QMessageBox.question(self, 'Erro', 'Operador ou senha incorreta', QMessageBox.Ok)
if msg == QMessageBox.Ok:
pass
Thank you very much, that’s what was missing, you are grade 10, no, grade 11!
– Samuel Cruz