Importing existing users from other platform (json data with bcrypt passwords)

EDIT: seems it’s not possible to keep the passwords.

Hi all,

I’m trying to port some old Express app (with MongoDB) to a Django app (with Postgresql).
I want to seed existing users from a JSON data file that was exported from a Mongo database it has some date/time stamps that I want to keep in the createdAt and updatedAt fields.

All users have passwords already encryption in bcrypt, Next, I want to preserve the _id in maybe some new old_id field to connect it to other data that need to be seeded to other tables later and also move all that extra data to a new profile model. I don’t even know If this is possible.

Here is a small sample of my JSON export data:

      "_id": "616224fec72679427a94b1ae",
      "accountType": "Personal",
      "businessName": "",
      "businessType": "",
      "defaultTip": "0",
      "disableAccount": "false",
      "email": "",
      "firstName": "John",
      "fullName": "John Doe",
      "lastName": "Doe",
      "password": "$2a$10$5n8iHFKcPAkpfxbR.JvLVu8auls7mPB0ckWRKwpDV8ZO0yPIDY7fe",
      "paymentType": "Cash",
      "phone": "(555) 444-5555",
      "town": "Random Town",
      "createdAt": "2021-10-09 23:25:50.0,422",
      "updatedAt": "2021-10-09 23:27:41.0,095",
      "zipCode": "90210"

Hope someone can help me with this like I don’t even know were to start I’m really new at Django but so sick and tired of JavaScript and my other option is use some PHP framework what is even worst!

Anyway thanks for even reading this far!

Sorry, this probably isn’t going to be reasonable. Unless you’re willing to port the hash function for the password from the original system and use that code to create your own password backend, it’s highly unlikely that the same passwords are going to be able to be kept.

I suggest you plan on having users reset their passwords.

If there is no other way, I was hoping that it used the default bcrypt settings there was a way to keep them. :frowning:

As long I can keep the rest of the data and dates working it’s not the end of the world.

If you read the docs for How Django stores passwords, you’ll see that the sample you posted doesn’t match the standard Django format. Unless you know what those components in the password are, and how they relate to Django’s standards, the built-in backends aren’t going to know how to handle it.

If you do know what that encoding represents, then you might be able to convert the data to Django’s format - that may be possible.

1 Like

Yeah you’re right forget about the passwords