java调用nodejs代码函数_使用bcrypt-nodejs的未定义函数

我正在使用bcrypt-nodejs在预保存函数中散列密码 . 我无法弄清楚为什么我继续在bcrypt.hash的回调函数中收到错误'[TypeError:undefined is not a function]' .

var mongoose = require('mongoose'),

validate = require('mongoose-validate'),

bcrypt = require('bcrypt-nodejs'),

SALT_WORK_FACTOR = 10,

REQUIRED_PASSWORD_LENGTH = 8;

function validateStringLength (value) {

return value && value.length >= REQUIRED_PASSWORD_LENGTH;

}

var schema = mongoose.Schema({

email: {type: String,

required: true,

unique: true,

validate: [validate.email, 'is not a valid email address']

},

passHash: {type: String,

required: true,

validate: [validateStringLength, 'The password must be of min ' + REQUIRED_PASSWORD_LENGTH + ' characters length.']}

});

schema.pre('save', function (next) {

var self = this;

if (!self.isModified('passHash')) return next();

bcrypt.hash(self.passHash, SALT_WORK_FACTOR, null, function encryptedPassword (err, hash) {

if(err) console.log(err);

self.passHash = hash;

next();

});

});

schema.set('autoIndex', App.env !== 'production');

var Model = mongoose.model('User', schema);

module.exports = Model;

我检查了传递的参数,它们是正确的 . 返回的哈希值也为null .

有没有人有类似的经历?我正在使用bcrypt-nodejs,因为bcrypt在使用npm进行安装时给出了错误 .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值