[英]How do i make a user profile so that i will input the name, mail etc. and then it saves, so i can login
class User:
def __init__(self, username, email, date_of_birth, password):
self.username = username
self.email = email
self.date_of_birth = date_of_birth
self.password = password
@staticmethod
def login_or_register():
userinput = input("login or register")
def register(self):
pass
def login(self, login_reg):
self.login_reg = login_reg
How do i make a user profile so that i will input the name, mail etc. and then it saves so i can login我如何制作用户配置文件,以便我输入姓名、邮件等,然后保存以便我可以登录
heres a really simple way to do it:这是一个非常简单的方法:
import hashlib
db = {}
hash = lambda x: hashlib.md5(x.encode()).hexdigest()
def register(user, password, mail):
db[user] = {"password": hash(password), "mail": mail}
def login(user, password):
if db[user]["password"] == hash(password):
print("success!")
else:
print("fail")
register("ironkey", "password123", "example@example.com")
login("ironkey", "password")
login("ironkey", "password123")
# get credentials for the user ironkey
print(db["ironkey"])
fail
success!
{'password': '482c811da5d5b4bc6d497ffa98491e38', 'mail': 'example@example.com'}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.