我正在将一个应用程序从解析迁移到流星。在解析中,用户的密码被存储为bcrypt(密码),而meteor则存储bcrypt(sha256(密码))。如何将旧的bcrypt列表插入到meteor,以便老用户能够无缝登录?
发布于 2016-07-06 20:50:49
我建议看一下帐户-密码是如何定义密码登录方法的,然后定义您自己的。方法签名 for registerLoginHandler.
在服务器中(建议在服务器启动期间执行此操作):
import bcrypt from 'bcrypt';
import { Accounts } from 'meteor/accounts-base';
import { Meteor } from 'meteor/meteor';
Accounts.registerLoginHandler('parsePassword', function (options) {
// Validate options
/* TODO Fill in yourself */
// Find the user to login
/* TODO Fill in yourself */
const result = {
userId: user._id,
};
// Prepare the bcrypt method
const bcryptCompare = Meteor.wrapAsync(bcrypt.compare);
if (! bcryptCompare(options.password, hashedPassword)) {
result.error = new Meteor.Error(403, 'Incorrect password');
}
return result;
});然后您将使用这个登录方法,就像在客户机上一样:
import { Meteor } from 'meteor/meteor';
Meteor.loginWithParsePassword({ user: /* TODO Define the query for finding your user */, password: passwordInput }, function () { console.log(arguments); });确保在package.json中列出bcrypt模块
我留下了部分示例空白,因为我不知道询问者是如何从Parse导入用户的,以及导入的数据的db结构是什么样的。因此,我将把代码的这一部分留作提问者进行的练习。
https://stackoverflow.com/questions/38225858
复制相似问题