密码管理器替换密码
Posted
技术标签:
【中文标题】密码管理器替换密码【英文标题】:Password Manager Replacing Passwords 【发布时间】:2021-03-13 17:03:52 【问题描述】:我想附加相同的网站帐户。但是当尝试在同一个网站上保存多个帐户时,它是替换密码。我究竟做错了什么? 这是我的代码:
def save():
websites = website_entry.get()
email = user_entry.get()
passwords = password_entry.get()
new_data =
websites:
"Email": email,
"Password": passwords,
if len(websites) == 0 or len(email) == 0 or len(passwords) == 0:
messagebox.showinfo(title="Oops!", message="Please give all the required information's")
else:
try:
with open("data.json", "r") as data_file:
data = json.load(data_file)
except FileNotFoundError:
with open("data.json", "w") as data_file:
json.dump(new_data, data_file, indent=4)
else:
data.update(new_data)
with open("data.json", "w") as data_file:
json.dump(data, data_file, indent=4)
finally:
user_entry.delete(0, END)
website_entry.delete(0, END)
password_entry.delete(0, END)
【问题讨论】:
【参考方案1】:问题是当您向其中添加新数据时,您正在以写入与追加模式打开data.json
:
with open("data.json", "w") as data_file:
json.dump(data, data_file, indent=4)
相反,您应该以附加模式打开 data.json
以避免覆盖文件的现有内容:
with open("data.json", "a") as data_file:
json.dump(data, data_file, indent=4)
【讨论】:
以上是关于密码管理器替换密码的主要内容,如果未能解决你的问题,请参考以下文章
1Password,Lastpass,Keepass,选择哪个做为密码管理器