带while循环的密码函数

2024-09-28 23:43:41 发布

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

你好,我这里有一个密码函数的while循环。该函数正在工作,我只是不能结束循环时,一个正确的密码输入

# Administrator accounts list
adminList = [
    {
        "username": "DaBigBoss",
        "password": "DaBest"
    },
    {
        "username": "root",
        "password": "toor"
    }
]


# Build your login functions below
def getCreds():
    username = input("What is your username? ")
    password = input("What is your password? ")



    return {"username": username, "password": password}



def checkLogin(adminList, user_info):
    if user_info in adminList:
        loggedIn = True
        print("------")
        print("YOU HAVE LOGGED IN!")


    else: 
        loggedIn = False
        print("------")
        print("Login Failed")

        return

logged = False

while not logged:
    user_info = getCreds()
    is_admin = checkLogin(adminList, user_info)
    if is_admin:
        logged = True

如果我键入正确的密码,我会得到我已登录的结果。但循环不会结束

结果

What is your username? d
What is your password? d
------
Login Failed
What is your username? root
What is your password? toor
------
YOU HAVE LOGGED IN!
What is your username?

Tags: 函数info密码yourisusernamerootpassword