Reputation: 5918
I am using this example to create a custom User model. I want to test this through django shell.
When I create a user from django shell using MyUser.objects.create(email='some@example.com', data_of_birth=datetime.date.today(), password='somepassword')
, the password doesn't get hashed and is stored in the database as plaintext.
But if I create a user through django admin portal, it gets stored as a hash.
What do I need to do so that it gets stored as hash even through shell? Do I need to implement some function of my own?
Django version 1.7.3
Upvotes: 4
Views: 5499
Reputation: 4060
staff = Staff()
staff.username = username
staff.set_password(password)
staff.save()
here staff is inherited model from USER , when user enter password you just give to the set_password , django automaticaly converted into hasble pwd
Upvotes: 1
Reputation: 53699
Use User.set_password()
:
user = MyUser(email='some@example.com'), ...)
user.set_password('somepassword')
user.save()
Upvotes: 11