生成 Django SHA1 密码

发布于 2024-10-21 19:55:08 字数 168 浏览 8 评论 0原文

我需要根据 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠檬色的秋千 2024-10-28 19:55:08

明白它是如何工作的了。我写了一个小函数来检查用户的密码:

def check_passwd (user, raw_password):
     import hashlib
     # ... get 'hsh_passwd' from database based on 'user' ...
     hsh_passwd = hsh_passwd.split('

当然,没有太多验证,而且不灵活,但这就是我一直在寻找的。

) salt = hsh_passwd[1] hsh = hsh_passwd[2] if hsh == hashlib.sha1(salt + raw_password).hexdigest(): return True return False

当然,没有太多验证,而且不灵活,但这就是我一直在寻找的。

Got it how it works. I wrote a small function to check a user's password:

def check_passwd (user, raw_password):
     import hashlib
     # ... get 'hsh_passwd' from database based on 'user' ...
     hsh_passwd = hsh_passwd.split('

Of course, there's not a lot of verifications and it's not flexible, but it's what I've been looking for.

) salt = hsh_passwd[1] hsh = hsh_passwd[2] if hsh == hashlib.sha1(salt + raw_password).hexdigest(): return True return False

Of course, there's not a lot of verifications and it's not flexible, but it's what I've been looking for.

没有你我更好 2024-10-28 19:55:08

创建和验证用户密码的完整代码位于 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 and User.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文