使用sqlite3生成登录函数

2024-04-25 06:02:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在做一个项目,需要一个登录系统,可以通过使用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("Welcome\n")

                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.OperationalError:no-this column:admin”。我已经在数据库中输入了用户名和密码,但是仍然出现这个错误。在

请帮忙


Tags: in数据库密码executeadmin系统usernamepas
1条回答
网友
1楼 · 发布于 2024-04-25 06:02:51

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

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

相关问题 更多 >