求助我这代码怎么保存新密码
password_list = ['*#*#','12345']def account_login():
tries = 3
while tries > 0:
password = input("请输入密码:")
password_correct = password == password_list[-1]
password_reset = password == password_list
if password_correct:
print('登录成功!')
break
elif password_reset:
new_password = input('请设置新密码:')
password_list.append(new_password)
password_list == password_list.pop(1)
print('你的密码已经重置!')
#account_login()
else:
print('密码错误,请重新输入!')
tries = tries - 1
print('还有',tries,'次机会')
else:
print('输入错误次数过多,已锁定')
account_login()
本帖最后由 jackz007 于 2021-3-9 22:44 编辑
把这三句代码:
new_password = input('请设置新密码:')
password_list.append(new_password)
password_list == password_list.pop(1)
改为:
password_list = input('请设置新密码:') . strip() 路径/文件名你自己改成自己用的就可以了,这样就可以实现永久保存修改的密码了
def account_login():
password_list = []
f = open('D:/Desktop/test/a/b/code.txt','r+')
password_list.append(f.readline(-1))
tries = 3
while tries > 0:
password = input("请输入密码:")
password_correct = password == password_list[-1]
password_reset = password == '*#*#'
if password_correct:
print('登录成功!')
break
elif password_reset:
new_password = input('请设置新密码:')
password_list.append(new_password)
password_list.pop(0)
f.writelines(password_list)
print('你的密码已经重置!')
#account_login()
else:
print('密码错误,请重新输入!')
tries = tries - 1
print('还有',tries,'次机会')
else:
print('输入错误次数过多,已锁定')
account_login()
页:
[1]