Auto commit

上级 df352508
print('欢迎来到 InsCode')
\ No newline at end of file
import json
# 加载已存储的密码数据
try:
with open('passwords.json', 'r') as f:
passwords = json.load(f)
except FileNotFoundError:
passwords = {}
# 菜单功能
def menu():
print('请选择操作:')
print('1. 存储密码')
print('2. 获取密码')
print('3. 删除密码')
print('4. 查看所有密码')
print('5. 退出程序')
# 存储密码
def save_password():
name = input('请输入网站或应用的名称:')
username = input('请输入登录用户名:')
password = input('请输入登录密码:')
passwords[name] = {'username': username, 'password': password}
with open('passwords.json', 'w') as f:
json.dump(passwords, f)
print('密码保存成功!')
# 获取密码
def get_password():
name = input('请输入要查看的网站或应用名称:')
if name in passwords:
print('账号:', passwords[name]['username'])
print('密码:', passwords[name]['password'])
else:
print('未找到该网站或应用的密码!')
# 删除密码
def delete_password():
name = input('请输入要删除的网站或应用名称:')
if name in passwords:
del passwords[name]
with open('passwords.json', 'w') as f:
json.dump(passwords, f)
print('密码删除成功!')
else:
print('未找到该网站或应用的密码!')
# 查看所有密码
def view_passwords():
if not passwords:
print('暂无保存密码!')
else:
for name, data in passwords.items():
print(name, ':', data['username'], '/', data['password'])
# 主循环
while True:
menu()
choice = input('请输入您的选择:')
if choice == '1':
save_password()
elif choice == '2':
get_password()
elif choice == '3':
delete_password()
elif choice == '4':
view_passwords()
elif choice == '5':
print('感谢使用密码管理器,再见!')
break
else:
print('输入有误,请重新输入!')
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册