0

I'm having a trouble on how can I dump a encrypted password data into authuser table in django, Currently I'm using python manage.py loaddata fixtures.json to dumpdata into database it works fine but the password is not encrypted, how can I encrypt it when using loaddata?. Is there any expert can share solutions or ideas with this problem, Much appreciate! enter image description here

   [{"model":"auth.user",
    "pk" : 2,
    "fields" : {"password" : "superadmin",
    "is_superuser" : "1",
    "username" : "superadmin",
    "first_name" : "name" ,
    "last_name" : "lname" ,
    "email" : "a@gmail.com" ,
    "is_staff" : "1",
    "is_active" : "1"
   }]
BootCamp
  • 444
  • 4
  • 18
  • Dumpdata always encrypt passwords. You may need to look at your code carefully – ANFAS PV Nov 04 '20 at 04:26
  • @ANFASPV thanks for your response, at first that's what I expected, when I createsuperuser using `python manage.py createsuperuser` it works fine it encrypt password but when I used that code above it didn't encrypt `"fields" : {"password" : "superadmin"` – BootCamp Nov 04 '20 at 05:18
  • @ANFASPV do you have any idea how Im going to encrypt password? – BootCamp Nov 04 '20 at 05:18

1 Answers1

0

Django don't store the raw password in the database. It just store the encrypt one in a column called password. When you create a password for your user in this way, you are populating this column with raw data. The "superadmin" is the encrypted password.

Try to use it to login, you notice it doesn't work, because "superadmin" isn't the password, it's just their value encrypted.

There are several alternatives, although honestly I don't like any of them: https://stackoverflow.com/a/34322435/10712525

Lucas Vazquez
  • 1,456
  • 16
  • 20