在下面概述的简单情况下,用户将成功导入,但在我尝试进行身份验证时收到INVALID_PASSWORD
。
salt
和passwordHash
使用{SSHA}身份验证架构从LDAP用户目录(apacheds)中提取。当我运行以下JS时,我收到了passwordHash
我期待的:
var sha1Hex = require('sha1-hex');
var saltHex = Buffer.from("ktuF+dzYMQU=", 'base64').toString('hex');
var passwordHex = Buffer.from("demo", 'utf-8').toString('hex');
var hash = sha1Hex(Buffer.from(passwordHex + saltHex, 'hex'));
var hashBase64 = Buffer.from(hash, 'hex').toString('base64');
console.log(hashBase64);
firebase CLM导入命令:
firebase auth:import users.json --hash-algo=SHA1 --rounds=80
users.json文件:
{
"users": [
{
"localId": "3c872eee-e86c-4b44-9840-bcebaac18f2c",
"email": "test@example.com",
"salt": "ktuF+dzYMQU=",
"passwordHash": "BuapoGGKIdfGprfMFjj3N9I7Ljg=",
"displayName": "Demo User",
}
]
}
适用于导入用户的凭据:
用户名:test@example.com
密码:demo
Firebase web api登录命令(返回INVALID_PASSWORD):
firebase.auth().signInWithEmailAndPassword('test@example.com', demo);
我对--rounds=80
参数没有信心,使用sha1时根本需要指定一些奇怪的东西。我也试过--rounds=0
。
答案 0 :(得分:1)
在使用Java MessageDigest SHA-1尝试验证密码哈希之后,我们的一位超级专家说,看起来你正在做passwordHash = SHA1(plainPassword + salt)
但是,Firebase Auth系统使用passwordHash = SHA1(salt + plainPassword)
。
所以我认为如果你改变它,它应该产生更好的结果。
答案 1 :(得分:1)
您可以配置密码和哈希的顺序。
hash-input-order
接受两个值:SALT_FIRST
或PASSWORD_FIRST
。
您想做的事:
firebase auth:import users.json --hash-algo=SHA1 --rounds=80 --hash-input-order=PASSWORD_FIRST
答案 2 :(得分:0)
对于像我这样花费大量时间寻找解决方案的人,请参阅this。
基本上,passwordHash
应该采用非十六进制的SHA1哈希的Base64编码。并且--rounds=1
可以正常工作。