【发布时间】:2021-12-22 14:34:27
【问题描述】:
我正在尝试创建从文本文件中获取的用户名和密码。用户名和密码在开头添加并在后面使用。我在开始时添加了用户名和密码,它可以工作。它将它添加到文本文档中,但它说当我输入 2 个先前创建的凭据时它不在文档上。我把我相信的部分放在**中。有什么办法可以正常工作吗?如果我的观点不清楚,我可以在必要时指定更多。谢谢。
import time
import sys
text1 = input("\n Write username ")
text2 = input("\n Write password ")
saveFile = open('usernames+passwords', 'r+')
saveFile.write('\n' + text1 + '\n' + text2 + '\n')
uap = saveFile.read()
saveFile.close()
max_attempts = 3
attempts = 0
while True:
print("Username")
username = input("")
print("Password")
password = input("")
*if username in uap and password in uap:
print("Access Granted")*
else:
attempts+=1
if attempts >= max_attempts:
print(f"reached max attempts of {attempts} ")
sys.exit()
print("Try Again (10 sec)")
time.sleep(10)
continue
break
【问题讨论】:
-
打印
uap看看它是什么。 -
你试过用
.readlines()代替.read()吗?