firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Using auth:import where PasswordHash = md5( secretKey + PlainTextPassword)

Open misterfresh opened this issue 9 years ago • 7 comments

Is this format supported ? It seems common on some legacy CMS. In user json I put "password": base64 encoded hash "salt": base64 encoded secret key where encoded hash = = md5( secretKey + Pass). The secret key is the same for all users. In CLI I entered : firebase auth:import users.json --hash-algo=MD5 rounds=0

Also tried without salt and with CLI command : firebase auth:import users.json --hash-algo=MD5 rounds=0 --hash-key=secretKey

In both cases the user was created but it was impossible to login. (error Invalid password)

misterfresh avatar Mar 20 '17 10:03 misterfresh

Sorry for the late response. MD5 doesn't require hash-key so specifying hash key won't work. I think put secret key at salt field should work. Could you provide a sample test user so that I can look into it?

wyhao31 avatar May 19 '17 21:05 wyhao31

For MD5, the user.json file should have "passwordHash" and "salt" specified like so:

{
  "users": [
    {
      "localId": "uid1",
      "email": "[email protected]",
      "emailVerified": true,
      "displayName": "Test",
      "passwordHash": "MjBmN2VjNzI0ZTY2MWJhZDEzMzM4MmQwZDUzNGIyZjc=",
      "salt": "cXdlcnR5"
    }
]}

Where you generate the salt like so:

var salt = 'qwerty';
var saltBase64 = new Buffer(salt).toString('base64'); //cXdlcnR5

and the Base64 encoded hash like so:

  var hash = crypto.createHash('md5').update(salt+users[i].password).digest('hex');
  var base64Hash = new Buffer(hash).toString('base64');

You can then import it using:

firebase auth:import users.json --hash-algo=MD5 --rounds=0

Note:

  • The md5 hash object is of the form salt+password
  • You need to digest the crypto hash to hex, before setting it to base64.

A complete example of how to upload is here

kmcnellis avatar Sep 15 '17 20:09 kmcnellis

@kmcnellis tried it exactly as you've described, does not work (anymore?). Did something change?

dswbx avatar Dec 22 '17 19:12 dswbx

What error are you getting?

kmcnellis avatar Dec 22 '17 20:12 kmcnellis

Sorry for not adding this info. When I successfully imported the users like you showed (and that works), I try to login with email and the plain password, and I'll get a "users password is not correct or user has no password" error.

dswbx avatar Dec 23 '17 10:12 dswbx

Hm. Still working fine for me. Did you try running the gist?

kmcnellis avatar Dec 24 '17 03:12 kmcnellis

@RSSfeed @misterfresh did you try the gist? Please reopen and provide a sample test user if this is still an issue.

kevinajian avatar Jan 09 '19 00:01 kevinajian