node.js - How to encrypt password(hashing) using bcrypt or anyother method in meteor(In case of no account-password package)? -
i new meteor
. created simple meteor app in want save user password hashed string, not plain password , don't want use accounts-password package. following meteor method 1 using 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 code in user signup route:
meteor.call("addrecord", newuser, function(err, result) { if(result) { console.log("successfully added new record 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 code not working, passwords saved same plain text.
Comments
Post a Comment