【发布时间】:2020-04-29 15:05:11
【问题描述】:
总之,我正在尝试创建一个密码管理器。想法是程序会询问用户输入。 如果用户写“new”,程序会要求在网站上输入用户名和密码,然后将这些数据以列表的形式存储在文本文件中。
现在主要问题:
我希望能够访问选定的数据并让程序将文本文件中的数据打印给我。 例如: 我在程序中输入网站“google”以及用户名:“potato”和密码:“potato”
之后,程序会询问我还想做什么。如果我写“访问 google”,我想通过编程将特定于 google 输入的网站、用户名和密码返回给我。
这是必要的,因为我将添加几个不同的输入。
我不知道该怎么做,也没有导师。我希望有人能给出一个我可以学习的解决方案。
您将在下面找到我提出的基本代码。
请记住,我是初学者。谢谢。
vault = open("Passvault.txt", "r+")
list = []
action = input("What do you want to do? ")
def tit():
global title
title = input("Add website: ")
return title
def user():
global username
username = input("Create username: ")
return username
def passw():
global password
password = input("Create password: ")
return password
running = True
while running:
creation = True
tit()
user()
passw()
if action == "new":
tit()
user()
passw()
#I added a class here hoping that i could create a class with an argument referencing the title
#so that when i type access "title" in the next if statement it would print back the data
#relevant to the selected title
class new(str(title)):
list.append(tit)
list.append(user)
list.append(passw)
vault.close()
if action == "access" + title:
creation = False
print(title)
print("Username: " + username)
print("Password: " + password)
vault.close()
【问题讨论】:
标签: python-3.x