0
我希望我的代码使用if语句来检查用户所在的用户组,然后为每个用户调用不同的函数。我当前的代码如下:SQLite3记录验证
c.execute('SELECT * from users WHERE username=? AND password =?',
(username_input, password_input))
if c.fetchone() is not None:
c.execute('SELECT usergroup from users WHERE username=? AND password=?',
(username_input, password_input))
user_group = c.fetchone()
for (usergroup,) in c:
if user_group == 1:
App.admin_login_successful(self)
elif user_group == 2:
App.user_login_successful(self)
else:
App.user_login_successful(self)
# This shouldn't happen, as all records should theoretically contain a value for usergroup.
我应该怎么做,使比较工作,我的记录确实包含的值是1或2,但验证不工作。
你从''之前在C(用户组)'打印(USER_GROUP)得到什么:'?我不确定你为什么要在你的for循环中创建一个元组。 – roganjosh
我为(usergroup,)做了c:关闭其他用户在这里的建议以防止SQL注入,但他的回答并不是非常清楚。当我打印时,我得到('2',) –
您正在从您的数据库中检索一些东西,所以如果要进行SQL注入,它已经发生了;我不确定这个建议是否有意义,或者是因为这个建议不符合上下文。摆脱'for'循环(你使用'fetchone()',所以你只能得到1个结果),并将'if' /'elif'检查改为'if int(user_group [0])== 1:'etc 。 – roganjosh