【发布时间】:2016-10-06 09:17:50
【问题描述】:
我正在编写一个使用基本身份验证的 python(3.4) 代码。我已将凭据(即用户名和密码)存储在文本文件 (abc.txt) 中。
每当我登录时,代码只接受文本文件的第一行并忽略其余凭据并给出不正确的凭据错误。
我的代码:
with open('abc.txt') as f:
credentials = [x.strip().split(':') for x in f.readlines()]
for username, password in credentials:
user_input = input('Please Enter username: ')
if user_input != username:
sys.exit('Incorrect incorrect username, terminating... \n')
user_input = input('Please Enter Password: ')
if user_input != password:
sys.exit('Incorrect Password, terminating... \n')
print ('User is logged in!\n')
abc.txt:
Sil:xyz123
smith:abc321
【问题讨论】:
-
请为您的问题使用更具体的标题。
标签: python python-3.4