Javascript 检查用户';meteor JS中的密码
在我的Meteor应用程序中,我想更改另一个用户的密码。我想知道在更改之前是否有办法获取旧密码 这是我的服务器端方法:Javascript 检查用户';meteor JS中的密码,javascript,meteor,Javascript,Meteor,在我的Meteor应用程序中,我想更改另一个用户的密码。我想知道在更改之前是否有办法获取旧密码 这是我的服务器端方法: updateuser(id,password, options) { try { Meteor.users.update({ _id: id }, { $set: options }) Accounts.setPassword(id, password, options) } catch (e) { re
updateuser(id,password, options) {
try {
Meteor.users.update({ _id: id }, { $set: options })
Accounts.setPassword(id, password, options)
}
catch (e) {
return false;
throw new Meteor.Error(500, 'updateUser error', e);
}
}
我想知道旧密码是否正确。旧密码是散列的,您无法获取,但如果您有明文,您可以检查它是否正确
您可以使用帐户。\u checkPassword(用户,密码)
方法来检查旧密码是否正确。它已经实施
user
应该是用户对象,password
应该是纯文本密码字符串
如果结果(对象)不包含error
属性,则密码是正确的
您还可以查看(获取灵感)用于处理对的调用的方法的详细信息,该方法会更改当前用户的密码
如果您不想将纯文本密码发送到服务器(通常最好不要发送纯文本版本),可以使用SHA256在客户端上对其进行散列,方法是将其传递给
帐户。_hashPassword(纯文本密码)
(在帐户密码
包中实现)
//在客户端上
>>>账户。_hashPassword(“foobar”);
{
“摘要”:“c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2”,
“算法”:“sha-256”
}
使用此函数的结果调用服务器方法。假设您的方法中的SHA256哈希密码为oldPassword
:
//on the server
const user = Meteor.users.findOne(userId);
Accounts._checkPassword(user, "wrongPassword");
// results in:
{ userId: 'theuserid',
error:
{ [Error: Incorrect password [403]]
error: 403,
reason: 'Incorrect password',
details: undefined,
message: 'Incorrect password [403]',
errorType: 'Meteor.Error' } }
Accounts._checkPassword(user, oldPassword);
// results in the following if the password is correct
{ userId: 'theuserid' }
“明文”的意思是密码输入的类型应该是“文本”而不是密码吗?不,我的意思是你需要一个包含密码的字符串,或者一个包含密码sha-256版本的对象(通过
SHA256(密码)
散列密码字符串的结果).那么我应该添加任何特定的包吗?所有内容都是通过帐户密码
包实现的。我添加了一些关于散列和检查密码的细节。无论如何,您似乎并没有将原始密码传递给该方法。它的目的是什么?你想要达到的目标是什么?你考虑过安全问题吗?