Reputation: 13
I built an API using the Django rest framework. When you access the /admin page and are logged in as a superuser you have the ability to create new user profiles. However, creating one from the /admin tab means that when the user's profile is created the password that is used does not get encrypted like it usually would if created from the /API tab. What do I need to add to encrypt the user's password even if it created in the /admin tab? If I need to upload any code or anything please let me know.
user = User(
email=email, is_staff=False, is_active=True,
is_superuser=False,
last_login=now, date_joined=now, **extra_fields
)
#save the password here:
user.set_password(password)
user = self.model(email=email, **extra_fields)
user.save(using=self._db)
return user
Upvotes: 0
Views: 234
Reputation: 1941
When you create user, set password of that user by user.set_password(password)
. The set_password(password)
takes password as raw and save to table as hashed. If you share your code, I will share which place you need to place the code.
Upvotes: 1