Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. function changePassword(email, newPassword, callback) {
  2.  
  3. var oracledb = require('oracledb');
  4. oracledb.outFormat = oracledb.OBJECT;
  5.  
  6. oracledb.getConnection({
  7. user : '',
  8. password : '',
  9. connectString : ''
  10. },
  11. function(err, connection) {
  12. if (err) {
  13. return callback(new Error(err));
  14. }
  15. bcrypt.hash(newPassword, numSaltRounds, function(err, hash) {
  16. if (err) { return callback(err); }
  17. connection.execute(
  18. ' select password as "password" = : hash, ' +
  19. ' from jsao_users ' +
  20. ' where email = :email ', [hash, email], { autoCommit: true },
  21. function(err, result) {
  22. if (err) {
  23. console.log(err);
  24. doRelease(connection);
  25. return callback(new Error(err));
  26. }
  27. doRelease(connection);
  28. callback(null, result.rowsAffected > 0);
  29. });
  30. });
  31.  
  32. // Note: connections should always be released when not needed
  33. function doRelease(connection) {
  34. connection.close(
  35. function(err) {
  36. if (err) {
  37. console.error(err.message);
  38. }
  39. });
  40. }
  41. });
  42. }
  43.  
  44. bcrypt.hash(newPassword, numSaltRounds, function(err, hash) { //this is the line
  45. if (err) { return callback(err); }
  46. connection.execute(
  47. ' select password as "password" = : hash, ' +
  48. ' from jsao_users ' +
  49. ' where email = :email ', [hash, email], { autoCommit: true },
  50. function(err, result) {
  51. if (err) {
  52. console.log(err);
  53. doRelease(connection);
  54. return callback(new Error(err));
  55. }
  56. doRelease(connection);
  57. callback(null, result.rowsAffected > 0);
  58. });
  59. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement