简体   繁体   English

Python - 如何存储输入的用户名/密码

[英]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.

相关问题 如何创建一个Python字典来存储多个帐户的用户名和密码 - How to create a python dictionary that will store the username and password for multiple accounts 如何建立一个包含来自Python用户输入的用户名和密码的URL? - How do you build a URL that contains a username and password from user input in Python? Python:如何比较从 a.txt 读取的两个列表(用户名和密码)与用户输入 - Python: how do I compare two lists (username & password) read from a .txt to a user input 检查Python中的密码和用户名输入是否匹配? - Check if password and username input match in Python? 通过 flask python 验证用户名和密码输入 - Verifying username and password input through flask python 如何从 Python 中的 CSV 文件验证用户名和密码? - How to verify username and password from CSV file in Python? 如何在Python中循环使用此列表中的用户名和密码? - How to loop over username and password from this list in Python? 通过搜索用户名从文件中获取密码并将该密码存储在变量中 - Grab password from a file by searching username and store that password in variable 如何向诸如username = password之类的函数输入参数? - how to input arguments to a function like username=password? 从密码和用户名获取tweepy身份验证 - python - Getting tweepy authentication from password and username
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM