0

Creating user using django rest framework, how to encrypt the user password.Need help with that. here is my view

class UserCreateAPIView(generics.CreateAPIView):

def post(self, request):
    serializer = UserSerializer(data=request.data)
    if serializer.is_valid():
        User(
            serializer.save()
        )
        return Response({"status":"sucess", "code":status.HTTP_201_CREATED, "details":serializer.data})
    return Response({"status":"unsuccessful", "code":status.HTTP_400_BAD_REQUEST, "detsils":serializer.errors})
2
  • 1
    What do you mean to create encrypted password? Are you trying to create user and save the encrypted password in database? If yes, you should see:stackoverflow.com/questions/43031323/…. If you uses, Userserializer django will save your password with encryption, you needn't worry about that. Commented Jan 8, 2020 at 6:43
  • 1
    you can follow this answer stackoverflow.com/a/29391122 Commented Jan 8, 2020 at 6:57

1 Answer 1

2

Django provides default password hashing technique using make_password method

from django.contrib.auth.hashers import make_password


print("your hashing password is  ", make_password(your password))

you can choose the different password hashing technique like md5,sha2,etc..

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',
)

configure your settings.py

Sign up to request clarification or add additional context in comments.

1 Comment

I didn't use like this method, anyway thanks for your help

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.