4

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='[email protected]', 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

1
  • staff = Staff() staff.username = username staff.set_password(password) here staff is inherited model from USER , when user enter password you just give to the set_password , django automaticaly converted into hasble pwd Commented Jan 23, 2015 at 11:59

2 Answers 2

11

Use User.set_password():

user = MyUser(email='[email protected]'), ...)
user.set_password('somepassword')
user.save()
Sign up to request clarification or add additional context in comments.

Comments

1
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.