python-3.x - 在python中迭代数据库的问题
问题描述
我正在学习编程,但我遇到了一些问题。如果有人能指出我做错了什么,那就太好了。我想编写一个小程序来执行以下操作:
- 要求用户输入他的位置、用户名和密码,然后按 ENTER。
- 连接到数据库并查看存储这些凭据的“account_tbl”。
- 验证凭据
- 给用户三个机会
- 三个试验后踢出用户
我已经设法以粗体显示所有内容。验证密码的逻辑似乎不正确。只有当我按照我在数据库中存储帐户的相同顺序输入凭据时,验证才有效。下面是该表的副本。
在我的示例中,我将使用表中的最后一个帐户并查看发生了什么。 在此处输入图像描述
在下面找到我的代码副本:
import sqlite3
connect_fworlddb = sqlite3.connect('fworld.db')
myCursor = connect_fworlddb.cursor()
myCursor.execute('SELECT * FROM account_tbl')
allusers = myCursor.fetchall()
for chances in range(3,0,-1):
xrole = input("Enter your Role: ")
xuserid = input("Enter your UserID: ")
xpassword = input("Enter your Password: ")
for user in allusers:
print(user) #i have added this part to print what's happening
if user[2]==xrole and user[0]==xuserid and user[1]==xpassword in user:
print("Found")
break
else:
print("Not Found")
if chances == 1:
print("User" + " " + xuserid + " " + "account has been locked.")
print("Please contact the system Administrator on ext. 5408")
解决方案
推荐阅读
- javascript - 避免考虑使用 IntersectionObserver 在边缘相交
- python - 如果我使用缓存的 gRPC 通道,pytest 会失败,仅在多个测试中
- java - 如何使用spring hibernate更改查询中的表名
- java - SDK 31 中的 requestRawExternalStorageAccess 是什么?
- c# - C# 和 ASP.NET MVC 5 / Web API
- jboss - 应该在生产环境中使用 (ccm) (use-ccm="true")
- redirect - 用于重定向到自定义 URL 的在线服务
- sql - 如果我们在 Select 查询的 where 子句中排除空行,是否有任何性能优势
- c++ - 如何初始化数组
, N> 带有初始化列表? - vba - 仅在清单文件中突出显示匹配的单词