用node使用crypto模块测试时页面显示Not a string or buffer是怎么回事

页面显示的结果
Not a string or buffer

TypeError: Not a string or buffer
at TypeError (native)
at Hash.update (crypto.js:119:16)
at f:\node\box\routes\index.js:36:22
at Layer.handle as handle_request
at next (f:\node\box\node_modules\express\lib\router\route.js:131:13)
at Route.dispatch (f:\node\box\node_modules\express\lib\router\route.js:112:3)
at Layer.handle as handle_request
at f:\node\box\node_modules\express\lib\router\index.js:277:22
at Function.process_params (f:\node\box\node_modules\express\lib\router\index.js:330:12)
at next (f:\node\box\node_modules\express\lib\router\index.js:271:10)

我的代码:
 router.post('/signup',function(req,res){
  var name = req.body.name,
      password = req.body.password,
      password_re = req.body['password-repeat'];
  if(password_re != password){
    req.flash('error','两次输入的密码不一样!');
    return res.redirect('/signup');
  }
  //生成md5
  var md5 = crypto.createHash('md5'),
      password = md5.update(req.body.password).digest('hex');
  var newUser = new User({
    name:req.body.name,
    password:password,
    email:req.body.email
  });
  User.get(newUser.name,function(err,user){
    if(user){
      req.flash('error','用户已经存在');
      return res.redirect('/signup');
    }
    newUser.save(function(err,user){
      if(err){
        req.flash('error',err);
        return res.redirect('/signup');
      }
      req.session.user = user;
      req.flash('success','注册成功!');
      res.redirect('/');
    });
  });
});
查看全部
qq_21325027
Leezy__
2015/09/13 12:56
  • node.js
  • 点赞
  • 收藏
  • 回答
    私信

1个回复