【问题标题】:data must be a string and salt must either be a salt string or a number of roundsdata 必须是字符串,并且 salt 必须是 salt 字符串或循环数
【发布时间】:2019-10-15 18:22:30
【问题描述】:

这是我得到的错误: 错误:数据必须是字符串,盐必须是盐字符串或轮数。 这是我编写的代码,用于使用他们的电子邮件 ID 在我的数据库中重置密码。 如果这不正确,谁能告诉我如何使用 oracle 数据库重置节点 js 中的密码。 错误在 bcrypt.hash 行中。

下面是整个代码:

function changePassword(email, newPassword, callback) {

    var oracledb = require('oracledb');
    oracledb.outFormat = oracledb.OBJECT;

    oracledb.getConnection({
        user          : '',
        password      : '',
        connectString : ''
      },
      function(err, connection) {
        if (err) {
          return callback(new Error(err));
        }
        bcrypt.hash(newPassword, numSaltRounds, function(err, hash) {
          if (err) { return callback(err); }
          connection.execute(
            ' select password as "password" = : hash, ' +
            ' from jsao_users ' +
            ' where email = :email ', [hash, email], { autoCommit: true },
            function(err, result) {
              if (err) {
                console.log(err);
                doRelease(connection);
                return callback(new Error(err));
              }
              doRelease(connection);
              callback(null, result.rowsAffected > 0);
            });
        });

        // Note: connections should always be released when not needed
        function doRelease(connection) {
          connection.close(
            function(err) {
              if (err) {
                console.error(err.message);
              }
            });
        }
      });
}

这是我得到错误的部分:

 bcrypt.hash(newPassword, numSaltRounds, function(err, hash) { //this is the line
          if (err) { return callback(err); }
          connection.execute(
            ' select password as "password" = : hash, ' +
            ' from jsao_users ' +
            ' where email = :email ', [hash, email], { autoCommit: true },
            function(err, result) {
              if (err) {
                console.log(err);
                doRelease(connection);
                return callback(new Error(err));
              }
              doRelease(connection);
              callback(null, result.rowsAffected > 0);
            });
        });

【问题讨论】:

  • numSaltRounds的值是多少?
  • 最好先检查 newPassword 和 numSaltRound 是否为假

标签: node.js salt node-oracledb


【解决方案1】:

当您将newPassword 作为数字传递时,会出现此错误。 因此,最好将newPassword 作为字符串传递,或者您可以将newPassword 转换为newPassword.toString() 之类的字符串。

示例。

  let newPassword = newPassword.toString();

  bcrypt.hash(newPassword, numSaltRounds, function(err, hash) {});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-13
    • 2022-07-14
    • 2020-05-05
    • 2017-05-06
    • 2019-11-04
    • 1970-01-01
    • 2020-08-29
    • 1970-01-01
    相关资源
    最近更新 更多