将密码添加到 Django 组模型

Add password to Django Group model

是否可以使用密码保护群组,以便用户只有在拥有群组密码的情况下才能加入该群组?

我知道可以使用

向组模型添加字段

Group.add_to_class('password', CharField(max_length=180, null=True, blank=True))

但是我怎样才能以安全的方式实施呢?我希望正确散列和存储密码。本质上,如何将 User 密码字段也添加到 Group

编辑:

源代码中 Group class 的文档字符串。

Groups are a generic way of categorizing users to apply permissions, or some other label, to those users. A user can belong to any number of groups.

Beyond permissions, groups are a convenient way to categorize users to apply some label, or extended functionality, to them.

我在这里使用的群组只是一个标签,我想在用户尝试加入时使用密码保护该标签。

在考虑了您在评论中的回复后,我相信您最好的选择是子类化 Group,然后在其中实施身份验证程序。然后,您可以使用 make_passwordcheck_passwordis_password_usable 中记录的函数 here 来管理身份验证过程。