使用 sqlite3 创建登录函数



我目前正在从事一个项目,该项目需要一个登录系统,该系统可以使用sqlite3通过数据库访问信息(用户名,密码(。这是当前的登录系统:

def UserLogin():
un = admin
pw = password
try:
statement = cur.execute("SELECT Username FROM Users")
for row in statement:
if un in row:
print("%s" % un)
pw_pas = cur.execute("SELECT Password FROM Users WHERE Username = %s" % (un))
if (pw in pw_pas):
print("Welcomen")
elif pw not in pw_pas:
print("Password is incorrect")
return
print("Username is incorrect")
except IOError:
print("This process could not be executed")
print("login successful")

问题是当我运行代码时,我收到一条错误消息,说"sqlite3.操作错误:没有这样的列:管理员"。我已经在数据库中输入了用户名和密码,但仍然收到此错误。

请帮忙

不要对 SQL 语句使用字符串替换。使用参数。

cur.execute("SELECT Password FROM Users WHERE Username = ?", (un,))

最新更新