[英]Python - How to store a username/password from input
I was wondering how to store a username and password from input, and put it into a sort of database that is on the same python file.我想知道如何从输入中存储用户名和密码,并将其放入同一个 python 文件上的某种数据库中。 I would want the username and password to only be saved for however long the file is open, and don't require any long term storage of the data, thanks in advance!
我希望用户名和密码只保存文件打开的时间,并且不需要任何长期存储数据,在此先感谢!
This pretty simple stuff so I'll just give you the short answer, but you should probably do some more research on this in the future, as well provide the code you've written.这是非常简单的东西,所以我只会给你一个简短的答案,但你将来可能应该对此做更多的研究,并提供你编写的代码。
credentials = {}
def create():
username = input('Username: ')
password = input('Password: ')
credentials[username] = password
def authenticate():
username = input('Username: ')
password = input('Password: ')
return credentials[username] == password
Use create() to create users and authenticate() to log users in使用 create() 创建用户并使用 authenticate() 登录用户
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.