类型错误:"digest"参数是必需的,并且不能未定义



我在通过 http://localhost:3000/auth/register 注册一个简单的平均应用程序时遇到主题错误,我只是使用mean init命令创建的。 pbkdf2crypto正在生成错误,我不知道在哪里查找它。

我做了很多不同的事情,比如清除 npm 缓存、使用 npm 重新安装等。请帮帮我。以下是一些更多信息。

Mean --version: 0.12.15
npm --version: 5.0.3
node --version: v8.1.0
bower --version: 1.8.0
gulp --version: CLI and Local: 3.9.1

model.UserSchema.methods.hashPassword代码 (D:\Projects\Mean\CampaignBuilderode_modules\meanio-users\server\models\user.js(

/**
 * Hash password
 *
 * @param {String} password
 * @return {String}
 * @api public
 */
UserSchema.methods.hashPassword = function(password) {
  if (!password || !this.salt) return '';
  var salt = new Buffer(this.salt, 'base64');
  return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64');
};

http://localhost:3000/api/register 注册页面调用,它会生成500 Internal Server Error

火狐浏览器显示以下响应:

TypeError: The "digest" argument is required and must not be undefined
at pbkdf2 (crypto.js:635:11)
at Object.exports.pbkdf2Sync (crypto.js:628:10)
at model.UserSchema.methods.hashPassword (D:ProjectsMeanCampaignBuildernode_modulesmeanio-usersservermodelsuser.js:165:17)
at model.<anonymous> (D:ProjectsMeanCampaignBuildernode_modulesmeanio-usersservermodelsuser.js:94:31)
at VirtualType.applySetters (D:ProjectsMeanCampaignBuildernode_modulesmongooselibvirtualtype.js:94:25)
at model.Document.set (D:ProjectsMeanCampaignBuildernode_modulesmongooselibdocument.js:656:12)
at model._handleIndex (D:ProjectsMeanCampaignBuildernode_modulesmongooselibdocument.js:587:14)
at model.Document.set (D:ProjectsMeanCampaignBuildernode_modulesmongooselibdocument.js:547:24)
at model.Document (D:ProjectsMeanCampaignBuildernode_modulesmongooselibdocument.js:71:12)
at model.Model (D:ProjectsMeanCampaignBuildernode_modulesmongooselibmodel.js:46:12)
at new model (D:ProjectsMeanCampaignBuildernode_modulesmongooselibmodel.js:3621:13)
at create (D:ProjectsMeanCampaignBuildernode_modulesmeanio-usersservercontrollersusers.js:86:24)
at Layer.handle [as handle_request] (D:ProjectsMeanCampaignBuildernode_modulesmeaniolibcore_modulesservernode_modulesexpresslibrouterlayer.js:95:5)
at next (D:ProjectsMeanCampaignBuildernode_modulesmeaniolibcore_modulesservernode_modulesexpresslibrouterroute.js:137:13)
at Route.dispatch (D:ProjectsMeanCampaignBuildernode_modulesmeaniolibcore_modulesservernode_modulesexpresslibrouterroute.js:112:3)
at Layer.handle [as handle_request] (D:ProjectsMeanCampaignBuildernode_modulesmeaniolibcore_modulesservernode_modulesexpresslibrouterlayer.js:95:5)
at D:ProjectsMeanCampaignBuildernode_modulesmeaniolibcore_modulesservernode_modulesexpresslibrouterindex.js:281:22
at Function.process_params (D:ProjectsMeanCampaignBuildernode_modulesmeaniolibcore_modulesservernode_modulesexpresslibrouterindex.js:335:12)
at next (D:ProjectsMeanCampaignBuildernode_modulesmeaniolibcore_modulesservernode_modulesexpresslibrouterindex.js:275:10)
at loadUser (D:ProjectsMeanCampaignBuildernode_modulesmeanio-usersservercontrollersusers.js:202:24)
at Layer.handle [as handle_request] (D:ProjectsMeanCampaignBuildernode_modulesmeaniolibcore_modulesservernode_modulesexpresslibrouterlayer.js:95:5)
at trim_prefix (D:ProjectsMeanCampaignBuildernode_modulesmeaniolibcore_modulesservernode_modulesexpresslibrouterindex.js:317:13)
at D:ProjectsMeanCampaignBuildernode_modulesmeaniolibcore_modulesservernode_modulesexpresslibrouterindex.js:284:7
at Function.process_params (D:ProjectsMeanCampaignBuildernode_modulesmeaniolibcore_modulesservernode_modulesexpresslibrouterindex.js:335:12)
at next (D:ProjectsMeanCampaignBuildernode_modulesmeaniolibcore_modulesservernode_modulesexpresslibrouterindex.js:275:10)
at D:ProjectsMeanCampaignBuildernode_modulesconnect-modrewriteindex.js:129:7
at Layer.handle [as handle_request] (D:ProjectsMeanCampaignBuildernode_modulesmeaniolibcore_modulesservernode_modulesexpresslibrouterlayer.js:95:5)
at trim_prefix (D:ProjectsMeanCampaignBuildernode_modulesmeaniolibcore_modulesservernode_modulesexpresslibrouterindex.js:317:13)

根据crypto.pbkdf2Sync方法,您缺少digest的最后一个参数,因此显示错误。

crypto.pbkdf2

此外,通过进一步调查,您可以看到 Node v6.0 中需要摘要参数。

以前的默认值似乎已被'sha1' .

这也可能是由于节点版本错误/运行的版本具有在您处于活动状态的节点版本中不支持的调用而导致

我的经验:我的团队有一个需要 Node 6.10.0 的应用程序。有时我忘记切换到此版本的节点并在 8.6.0 下运行最新代码,并且收到相同的错误。 一旦我交换回6.10.0,网站将允许我登录。

(我可以看到接受的答案也提到了这一点,但我想添加一个更明显的答案,以防它帮助那里的人!

相关内容

  • 没有找到相关文章

最新更新