[Fixed]-How to store Django hashed password without the User object?

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
👤MIkee

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()

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….

here is the hash password saved in database

Leave a comment