python3。验证字典中的用户名和密码

时间:2019-02-19 06:14:49

标签: python-3.x function authentication

我在一个函数中创建了一个字典。然后,我想创建另一个函数来检查和验证用户是否在词典中。但这总是给我一个错误。请帮忙。谢谢。我的代码如下:

def getCreds():   

    userInfo = []
    while (True):
        name = input("what is your user name? ")
        password = input("what is your password? ")


        userInfo.append({
            "name": name,
            "password": password,
            })

        cont = input("Want to add another? (Y/N)")
        if cont == "N":
            break
        print("Administrator account list : ")        
        print(userInfo)

def old_user():
    login = input("enter login name: ")
    password = input("enter password: ")


    userInfo()
    if login in userInfo and userInfo[login] == password:
        print("successful! ")
    else:
        print("No! ")
    #return getCreds()

getCreds()  
old_user()      

0 个答案:

没有答案