Accounts.registerLoginHandler with passwords in Meteor

久未见 提交于 2020-01-05 08:18:14

问题


I'm new to meteor and am stuck on registering a login handler that lets me use the password to authenticate the user.

I'm working off the code from http://meteorhacks.com

The server side code is as follows:

Accounts.registerLoginHandler(function(loginRequest) {
var userId = null;
var user = Meteor.users.findOne({'emails.address': loginRequest.email, password: loginRequest.password, 'proile.type': loginRequest.type});
if(user) {
  userId = user._id;
}
return { id: userId}

This works fine if I take out the password field and just use the email and type ones. How do I get this working with the password as well?


回答1:


Bottom line, you can't directly search via the plaintext password. You need to verify the password via SRP which is a little tricky as there isn't any documentation on it. Luckily Meteor is open source! A good start is at the accounts-password : https://github.com/meteor/meteor/blob/master/packages/accounts-password/password_server.js

There already is a package that can do password logins for you (the one the above file is from). You can add it to your project via meteor add accounts-password.

Then you could login with Meteor.loginWithPassword



来源:https://stackoverflow.com/questions/17275322/accounts-registerloginhandler-with-passwords-in-meteor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!