生成 Django SHA1 密码
我需要根据 Django 中已创建的用户,从另一个 python 软件提供对 Django 数据库的访问。我对整个访问过程很满意,我只需要一段代码来生成 Django 密码,就像管理身份验证模块一样。
最好的方法是什么?请注意,如果可能的话,我不想为此拥有整个 Django 包。
非常感谢
I need to provide access to a Django database from another python software based on the users already created in Django. I'm ok with the whole access thing, I just need a piece of code to generate a Django password as the admin auth module does.
What would be the best way of doing that? Note that, if possible, I don't want to have the whole Django package for that.
Many Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
明白它是如何工作的了。我写了一个小函数来检查用户的密码:
当然,没有太多验证,而且不灵活,但这就是我一直在寻找的。
Got it how it works. I wrote a small function to check a user's password:
Of course, there's not a lot of verifications and it's not flexible, but it's what I've been looking for.
创建和验证用户密码的完整代码位于
django.contrib.auth.models
。具体来说,查看方法
User. set_password
和 <代码>User.check_password。您需要提取这两位以及它们引用的 Django 代码,以根据 Django 创建和验证项目的用户密码。The entire code for creating and verifying user passwords is in
django.contrib.auth.models
.Specifically, look at the methods
User.set_password
andUser.check_password
. You'd need to extract those two bits and the Django code they reference to create and verify the project's user passwords as per Django.