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 packa开发者_运维知识库ge for that.
Many Thanks
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('$')
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.
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.
加载中,请稍侯......
精彩评论