我正在为我的班级做一个项目,我被困在这个额外的学分部分。我正在构建一个密码和用户名检查器来检查具有用户名和密码的字典列表。
我尝试了很多方法,但似乎无法得到我需要的结果。我拥有的代码的问题是它没有将密码与关联的用户名进行比较。如果密码在任何字典中,则结果为 TRUE。任何帮助将不胜感激,因为我将继续自己努力
This is what I have:
adminList = [
{
"username": "DaBigBoss",
"password": "DaBest"
},
{
"username": "root",
"password": "toor"
}
]
#Import Required Tools
import getpass
####################################
### Define ALL FUNCTIONS ###
####################################
#Define function to confirm login credntials of the user
def getCreds():
user_name = input("Please input your user name: ")
while not any(d["username"] == user_name for d in adminList):
print("User name not recognized, please try again.")
getCreds()
pass_word = getpass.getpass("Please enter your password: ")
print("Checking Credentials")
while not any(d["password"] == pass_word for d in adminList):
print("The password in not correct")
pass_word = getpass.getpass("Please enter your password again: ")
else:
print ("Hello and welcome to the Matrix.")
#Call the getCreds function
getCreds()