无法将用户导入Firebase,哈希问题

时间:2019-10-22 15:30:32

标签: node.js firebase firebase-authentication sha1 pbkdf2

我无法成功将用户导入Firebase。

我有一个用户列表,我只知道该用户的盐和哈希密码。我知道用于创建哈希的函数是以下(crypto lib for nodejs):

crypto.pbkdf2(password, salt, 20, 44, "sha1", callback)

我发现this website在给定相同配置(四舍五入和加盐)时给了我完全相同的哈希值。

我尝试过通过这种方式将用户导入Firebase,但没有成功:

admin
  .auth()
  .importUsers(
    [
      {
          uid: "9",
          email: "testuser@test.com",
          //password = testPassword
          passwordHash: Buffer.from("C6B7Uch6Q+NiiUZVqjRqPit9e+56YkA0xwwZtfs0+RI=",'base64'),
          passwordSalt: Buffer.from("testSalt",'base64'),

      }
    ],
    {
      hash: {
          algorithm: "PBKDF_SHA1",
          rounds: 20,
          dk_len: 44
      }
    }
  )
  .then(function(results) {
    results.errors.forEach(function(indexedError) {
      console.log("Error importing user " + indexedError.index);
    });

      firebase.auth().signInWithEmailAndPassword("testuser@test.com", "testPassword")

          .then(function(ok){
              console.log("It's working");
      })

          .catch(function(error) {
               var errorCode = error.code;
               var errorMessage = error.message;
               console.log(error);
      });

  })
  .catch(function(error) {
    console.log("Error importing users:", error);
  }); 

哪个给我:

{ [Error: The password is invalid or the user does not have a password.]

有些事情我不知道,我尝试了很多事情,包括更改firebase哈希配置中的算法,更改Base64,使用hash_input_order或更改key-len。

基本上我迷路了,很想帮助解决这个问题,有人知道吗?

谢谢。

0 个答案:

没有答案