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.
Asked
Active
Viewed 666 times
1
-
2Django's default auth model saves the password as ***hashed password***. You can use that feature – JPG Aug 13 '18 at 05:23
-
Refer this link, [Password management in Django](https://docs.djangoproject.com/en/2.1/topics/auth/passwords/) – JPG Aug 13 '18 at 05:24
-
i need without using authentication – ganesh s Aug 13 '18 at 05:29
-
1Why do you want to reinvent the wheel? – JPG Aug 13 '18 at 05:34
-
i want to know how to do it without authentication. – ganesh s Aug 13 '18 at 05:39
-
Here is a simple example of how ***ciphertext*** can be generated. After generating chiphertext, save it to your model field – JPG Aug 13 '18 at 05:51
-
where is the sample example bro, i didnot found any sample example – ganesh s Aug 13 '18 at 05:55
-
opps.. my bad .. https://stackoverflow.com/questions/27335726/how-do-i-encrypt-and-decrypt-a-string-in-python – JPG Aug 13 '18 at 05:58
1 Answers
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