1
votes

I've been working on migrating an existing app into Firebase Authentication, and I need to import the user passwords into Firebase to avoid everybody having to go through a password reset. I setup a test user and imported him in, but after the import I'm finding that Firebase rejects the user's password.

I'm submitting this JSON File:

{"users": [{"localId": "5e722b92dd784e7fa37b98f94790a87e", "email": "[email protected]", "emailVerified": true, "passwordHash": "6ZoYxCjLONXyYIU2eJIuAw==", "displayName": "Test"}]}

I've tried adding "salt": "" to the above, but it had no effect.

I'm executing with this command:

firebase auth:import firebaseUsers.json --hash-algo=MD5 --rounds 0 --project projectname

Which runs successfully and does add the user. But the user just gets "The password provided is incorrect or the user does not have a password set" when I try to log in with them.

The value "rounds" is something that I took from examples online. I've also tried 1, 4, and 64, without success.

The password on this test account is abc123. I've confirmed that the base64 MD5 of abc123 is 6ZoYxCjLONXyYIU2eJIuAw== with this Python:

import hashlib
import codecs
import base64
m = hashlib.md5()
m.update("abc123".encode('utf-8'))
print (base64.b64encode(codecs.decode(m.hexdigest(), 'hex')).decode())

Which does indeed output 6ZoYxCjLONXyYIU2eJIuAw==

Can anybody hows gone through this process before see what I've done wrong here?

1

1 Answers

0
votes

The problem with the code in the question is that it has converted the hex digits of the MD5 to base64. What you actually need to do is convert the string of the hex digits to base64. So using the above as an example

The MD5 of abc123 is 'e99a18c428cb38d5f260853678922e03'. You need to convert this to base64 as a string, which equals 'ZTk5YTE4YzQyOGNiMzhkNWYyNjA4NTM2Nzg5MjJlMDM='

Here is the corrected version of the code in the question:

m = hashlib.md5()
m.update("abc123".encode('utf-8'))
hexmd5 = codecs.decode(m.hexdigest(), 'hex')
print(base64.b64encode(bytes(m.hexdigest(), 'utf-8')).decode())