This is the error I am getting: Error: data must be a string and salt must either be a salt string or a number of rounds. This is the code that i have written is for resetting the password in my db using their email id. If this is not correct can anyone tell me how to reset the password in node js using oracle database. The error is in the bcrypt.hash line.
Below is the whole code:
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);
}
});
}
});
}
And this is the part where I am getting the error:
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);
});
});