两个列表,1有密码,2有用户名。如果同时使用了第一项(或第二项或第三项),程序如何才能允许访问

2024-06-11 02:08:35 发布

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

dic(zip(['example@example.co.uk','thing@thing.co.uk','email@email.co.uk'],
['Games','English','Piano']

我如何告诉计算机,只有输入了第一封电子邮件和第一个密码,而不是第一封电子邮件和第二个密码或第三个密码,并且两个密码都输入正确,才能访问帐户(与第二封电子邮件和密码相同,第三封等)


Tags: 密码englishexampleemail计算机帐户zipgames
1条回答
网友
1楼 · 发布于 2024-06-11 02:08:35

如果要将密码存储为字符串(这不是很安全),可以尝试以下方法(Python3):

passwords = dict(zip(['example@example.co.uk','thing@thing.co.uk','email@email.co.uk'], ['Games','English','Piano']))

#Get password from user (an example for console, please use a safer way)
email = input("Enter your e-mail adress: ")
password = input("Enter your password: ")

try:
    if passwords[email] == password:
        #log in
    else:
        print("This password is wrong")
except KeyError:
    print("This account does not exist")

相关问题 更多 >