Working with Passwords
class User(Base):
__tablename__ = "user"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String(50))
hashed_password: Mapped[str] = mapped_column(String)class UserAdmin(ModelView, model=User):
column_labels = {"hashed_password": "password"}
form_create_rules = ["name", "hashed_password"]
form_edit_rules = ["name"]
async def on_model_change(self, data, model, is_created, request) -> None:
if is_created:
# 在保存到数据库之前对密码进行哈希处理!
data["hashed_password"] = data["hashed_password"] + "_hashed"最后更新于