1

I have a user model in Django models, password is one of the field in users table. While saving user the password should be saved to database as encrypted. I am using Django Rest Framework to post the users and I don't want to use authentication.

TheKalpit
  • 1,426
  • 1
  • 14
  • 26
ganesh s
  • 21
  • 1
  • 7

1 Answers1

2

Django provides user authentication built-in. Link to official documentation: https://docs.djangoproject.com/en/dev/topics/auth/

To answer your question, considering you don't want to/can't use built-in authentication. You can encrypt the password field using make_password function. Django Auth uses the same to encrypt & authenticate user.

Before saving model, set encrypted password to field. Preferably in model class itself.

from django.contrib.auth.hashers import make_password
model.password = make_password(plaintext_password)
model.save()
TheKalpit
  • 1,426
  • 1
  • 14
  • 26