I am have created a node library file called encrypt.js
.
Within that are some functions created using bcrypt-nodejs
var bcrypt = require('bcrypt-nodejs');
exports.cryptPassword = function(password, callback) {
bcrypt.genSalt(10, function(err, salt) {
if (err) return callback(err);
else {
bcrypt.hash(password, salt, function(err, hash) {
return callback(err, hash);
});
}
});
};
exports.comparePassword = function(password, userPassword, callback) {
bcrypt.compare(password, userPassword, function(err, isPasswordMatch) {
if (err) return callback(err);
else return callback(null, isPasswordMatch);
});
};
When I now use cryptPassword
from my server.js
file it shows an error coming from the bcrypt-nodejs
library stating 'no callback function was given
'
I have added a function within my call as below
var encryptedPassword = encrypt.cryptPassword(req.body.user.password, function (err, salt){
if(err) {throw err};
console.log('hlllll');
});
Can anyone help?
Syntax: bcrypt.hash(data, salt, progress, cb)
You must have two callbacks.
Document here:
https://npmjs.org/package/bcrypt-nodejs
Update:
You can use the package bcrypt
instead of bcrypt-nodejs
And your code will work:
bcrypt.hash(password, salt, function(err, hash) {
return callback(err, hash);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With