我的期望是实现多账户的登录,符合数据库表的任何用户名Tuser和密码Tpassword都可以进行登录,该如何实现当输入用户名和密码时首先从指导老师表中遍历Tuser和Tpassword,然后进行判断登录
def login(self):
"""
用户登录判断,根据用户名识别用户所属系统,并在对应的数据库中进行登录验证,
成功则打开相应系统的主窗体。
:return:
"""
def check_network_connection():
try:
# 尝试连接到知名的公共DNS服务器
socket.create_connection(('8.8.8.8', 53))
return True # 连接成功,表示网络状态正常
except OSError as e:
return False # 连接失败,则表示当前状态无网络
if not check_network_connection(): # 判断网络是否连接
self.x = show_custom_message_box("注意!!!", "当前状态无网络,请检查网络连接")
return
userName = self.userName.text()
password = self.password.text()
if userName.strip() == '' or password.strip() == '':
self.x = show_custom_message_box("系统提示", "用户名或密码不能为空!")
else:
pass
"""用户实体类"""
class Tea:
# 编号
TID = None
# 姓名
Tname = None
# 年龄
Tage = None
# 性别
Tsex = None
# 联系电话
Tphone = None
# 住址
Taddress = None
# 用户名
Tuser = None
# 密码
Tpassword = None
def __init__(self, TID, Tname, Tage, Tsex, Tphone, Taddress, Tuser, Tpassword):
self.TID = TID
self.Tname = Tname
self.Tage = Tage
self.Tsex = Tsex
self.Tphone = Tphone
self.Taddress = Taddress
self.Tuser = Tuser
self.Tpassword = Tpassword
"""数据访问对象"""
from Util import dbUtil
from entity.TuserModel import Tea
# 记录当前用户
current: Tea = None
def login(tuser: Tea):
con=None
try:
con=dbUtil.getCon()
cursor=con.cursor()
cursor.execute(f"SELECT * FROM Teacher WHERE Tuser='{tuser.Tuser}' AND Tpassword='{tuser.Tpassword}'")
return cursor.fetchone()
except Exception as e:
print(e)
finally:
dbUtil.closeCon(con)