将外部用户导入firebase



我想将用户从外部数据库导入firebase。

密码是用sha256函数散列的,密码前面加了一个salt(这是一个UUID(。

例如:

password = "123qwerty!"
salt = "cb60eb29-95a2-418e-be2a-c1c107fb1add"
hash = sha256(salt+password)
# 54ccb21d42c6961aa1b666b7cb0485f85aab2f2323399fb2959ea5e4e9f6f595

现在要将此导入firebase,我将执行以下操作:

users = []*auth.UserToImport
users = append(users, (&auth.UserToImport{}).
UID("some-uid").
Email("jon.foo@example.com").
PasswordHash([]byte("54ccb21d42c6961aa1b666b7cb0485f85aab2f2323399fb2959ea5e4e9f6f595")).
PasswordSalt([]byte("cb60eb29-95a2-418e-be2a-c1c107fb1add")).
DisplayName("Jon FOO"))
h := hash.SHA256{
Rounds:     1,
InputOrder: hash.InputOrderSaltFirst,
}
res, err := cl.ImportUsers(ctx, users, auth.WithHash(h))
if err != nil {
log.Fatal(err)
}

用户在firebase中导入得很好(我可以在控制台中看到(,但当我尝试登录时,我出现了以下错误The password is invalid or the user does not have a password.

我看不出我的方法有什么问题,也许Rounds参数应该更新,但更新到什么值?

谢谢!

我终于找到了我的问题。在我的情况下,我将密码的十六进制表示形式作为PasswordHash

PasswordHash([]byte("54ccb21d42c6961aa1b666b7cb0485f85aab2f2323399fb2959ea5e4e9f6f595")).

事实证明,我必须首先解码密码,如下所示:

decoded, err := hex.DecodeString("54ccb21d42c6961aa1b666b7cb0485f85aab2f2323399fb2959ea5e4e9f6f595")
if err != nil {
return err
}
user := (&auth.UserToImport{}).
PasswordHash(decoded).
PasswordSalt([]byte("cb60eb29-95a2-418e-be2a-c1c107fb1add")). // the salt stays the same
...
// call ImportUsers with the same hash configuration (Rounds: 1, InputOrder: SaltFirst)

更新后,我运行了代码,现在可以与导入的用户进行身份验证了。

快速提示:正如评论中所提到的,node SDK没有指定输入顺序的选项(首先是salt或密码(,这似乎是一个重要的缺失功能。

相关内容

最新更新