问题
I have a running wiki with users. Now I want to write an app in Django to do a specific task.
I have to use my "old" users/groups database (which has a different hashing algorithm for passwords then django_auth) and sync it every now and then since my users already have a login which has to be the same everywhere.
I want to use django_auth as well.
Is it possible to change the Hashing algorithm in django_auth?
so that django auth uses a function I write to check whether the password inserted is right or wrong.
Thanks in advance, Senad. =)
回答1:
From Integrating with an Authentication System, chapter18 of djangobook
It’s possible to integrate Django with an existing authentication system — another source of usernames and passwords or authentication methods. You can override Django’s default database-based scheme, or you can use the default system in tandem with other systems.
Also, in this book, you can learn how to write your own Authentication Backend implementing two methods: get_user(id) and authenticate(**credentials).
回答2:
You can write a custom authentication backend that includes its own authenticate
function to check passwords according to your custom hash. Of course, you'll need some way of distinguishing between the different types of users.
回答3:
Yes it's possible. See django-bcyrpt for an example. It will be easier to change in Django 1.4: https://docs.djangoproject.com/en/dev/releases/1.4/#improved-password-hashing
来源:https://stackoverflow.com/questions/8794512/is-it-possible-to-change-the-hashing-algorithm-in-django-auth