【发布时间】: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