Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor 如何将account js包集成到已有的mongo db?_Meteor_Meteor Accounts - Fatal编程技术网

Meteor 如何将account js包集成到已有的mongo db?

Meteor 如何将account js包集成到已有的mongo db?,meteor,meteor-accounts,Meteor,Meteor Accounts,我有一个流星应用程序,想迁移非流星应用程序。我发现帐户js与meteor帐户系统兼容。当我创建新用户时,一切都很好,但如果我想用已经存在的用户帐户登录,js方法不起作用,每次我都会收到未经验证的消息。如何使用帐户js登录已有用户 const accountsPassword = new AccountsPassword({ verifyPassword: (plainPassword, storedPassword) => { const hashedPassword

我有一个流星应用程序,想迁移非流星应用程序。我发现帐户js与meteor帐户系统兼容。当我创建新用户时,一切都很好,但如果我想用已经存在的用户帐户登录,js方法不起作用,每次我都会收到未经验证的消息。如何使用帐户js登录已有用户

   
const accountsPassword = new AccountsPassword({
  verifyPassword: (plainPassword, storedPassword) => {
    const hashedPassword = crypto.Hash('sha256').update(plainPassword).digest('hex')

    console.log('*****Verify Password*****')
    return bcrypt.compareSync(plainPassword, storedPassword)
  }
})

const accountsServer = new AccountsServer(
  {
    db: accountsMongo
  },
  {
    password: accountsPassword
  }
)

const accountsGraphQL = AccountsModule.forRoot({ accountsServer })


const schema = makeExecutableSchema({
  typeDefs: mergeTypeDefs([typeDefs, accountsGraphQL.typeDefs]),
  resolvers: mergeResolvers([resolvers, accountsGraphQL.resolvers]),
  schemaDirectives: {
    ...accountsGraphQL.schemaDirectives
  }
})

const schemaMiddleware = applyMiddleware(schema, permissions)

帐户js使用了与Meteor身份验证系统完全不同的身份验证机制。帐户js使用JWT令牌,而Meteor使用唯一的散列,因此不具有交叉兼容性。我写了一篇关于它的博客文章,你可以阅读

帐户js如何散列它的密码?使用十六进制编码的sha256哈希在代码中显示它的方式?如果是这样,那就行不通了。如果您查看meteor帐户密码创建的散列密码,它们甚至不是十六进制的,例如,
“services”:{“password”:{“bcrypt”:$2b$10$L6HP23tUgsYuQ0LVwPXw1eODKLyDPvvxXo1IjZEx6.PBxfOeQHqS.}。
您可能是对的,但实际问题是“验证密码”当我使用数据库中已经存在的用户登录时,方法不会被任何触发。如果我创建了一个新用户,“verifyPassword”方法被触发并且运行良好。如果我在尝试使用数据库中已有的用户登录时实现了触发器验证方法,我可以测试哈希机制,但我还无法实现。谢谢你的评论。顺便说一句。非常感谢!