I am new to the meteor
. I just created simple meteor app in which I want to save the user password as hashed string, not the plain password and I don't want to use accounts-password package. Following is my meteor method which one I am using for User insertion process.
Meteor.methods({'addRecord':function(user) {
var checkCollection = Users.findOne({},{sort:{userId:-1}});
if(typeof checkCollection != 'undefined' || checkCollection){
currentId = Users.findOne({},{sort:{userId:-1}}).userId || "1";
user.userId = (currentId * 1) + 1;
bcrypt.genSalt(10, Meteor.bindEnvironment(function (err, salt) {
if (err)
return
bcrypt.hash(user.password, salt, Meteor.bindEnvironment(function (err, hash) {
if (err)
return;
user.password = hash;
Users.insert(user);
}));
}));
return user.userId;
}
else {
user.userId = "1";
Users.insert(user);
}
return 1;
}
});
and following is my code in user signup route:
Meteor.call("addRecord", newuser, function(err, result) {
if(result) {
console.log("Successfully added new record with auto_inc id " + result);
Utility.response(context, 200, {
'success': true,
'error': false,
'successText': 'Signup successful!'
});
} else {
console.log(err);
Utility.response(context, 200, {
'success': false,
'error': true,
'successText': 'Signup failed!'
});
}
});
but the code is not working, passwords get saved as same plain text.