40👍
You are on the right track. However you can manage the password manually using
from django.contrib.auth.hashers import make_password
print "Hashed password is:", make_password("plain_text")
Hasher configuration will be driven by PASSWORD_HASHERS which should be common for both the auth system and your UserActivation model. However you can pass it in make_password
method also.
PASSWORD_HASHERS = (
'myproject.hashers.MyPBKDF2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
'django.contrib.auth.hashers.BCryptPasswordHasher',
'django.contrib.auth.hashers.SHA1PasswordHasher',
'django.contrib.auth.hashers.MD5PasswordHasher',
'django.contrib.auth.hashers.CryptPasswordHasher',
)
Hope this helps.
Read this link for more details:
https://docs.djangoproject.com/en/dev/topics/auth/passwords/
44👍
The accepted answer was helpful to me – I just wanted to add the check_password call (for people like me, who haven’t used this functionality before)
from django.contrib.auth.hashers import make_password, check_password
hashed_pwd = make_password("plain_text")
check_password("plain_text",hashed_pwd) # returns True
- How do I install Mezzanine as a Django app?
- Import m2m relation in django-import-export
- How can I disable a model field in a django form
- Add confirmation step to custom Django management/manage.py command
- Google.maps.event.addDomListener() is deprecated, use the standard addEventListener() method instead : Google Place autocomplete Error
2👍
I solved it recently by doing the following steps:
from .models import Client
from django.contrib.auth.hashers import make_password
from .forms import ClientForm
form = ClientForm(request.POST)
if form.is_valid():
first_name = form.cleaned_data['first_name']
family_name = form.cleaned_data['family_name']
password = make_password(form.cleaned_data['password'])
phone = form.cleaned_data['phone']
user = Client(first_name=first_name, family_name=family_name, password=password, phone=phone)
user.save()
- Many to many relationships with additional data on the relationship
- Django bulk create objects from QuerySet
- Python Social auth authentication via access-token fails
0👍
views.py
from django.contrib.auth.hashers import make_password, check_password
print("password hashing!!!!")
password = make_password('password')
print(password)
signup_obj = Signuup(firstname=first_name,
lastname=last_name,
email=email,
password=password)
signup_obj.register()
password = make_password(‘password’) that will convert the password to hash but must use that code of line before register/save the object….