0
votes

I am converting php website to django. I have to match the password of a user during login. For hashing the password in cakephp

Security::setHash('blowfish');
Security::setCost(7);

Now I have to find same hashing function in django. I went through the this and found out that they use bcrypt to hash the password in CakePhp. I am beginner in Django and Can not figure out how to encrypt the password using bcrypt in Django specially setCost() function so that hashed password is same as in CakePhp.

1

1 Answers

0
votes

https://docs.djangoproject.com/en/3.2/topics/auth/passwords/#using-bcrypt-with-django

Using bcrypt with Django

  1. Install the bcrypt library. This can be done by running python -m pip install django[bcrypt], which is equivalent to python -m pip install bcrypt (along with any version requirement from Django’s setup.cfg).

  2. Modify PASSWORD_HASHERS to list BCryptSHA256PasswordHasher first. That is, in your settings file, you’d put:

PASSWORD_HASHERS = [
    'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
    'django.contrib.auth.hashers.PBKDF2PasswordHasher',
    'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
    'django.contrib.auth.hashers.Argon2PasswordHasher',
]

Now, when using the django User class, bcrypt would be used to hash the passwords when calling the User.set_password() functionality.