BcryptParse.mjs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * @author n1474335 [n1474335@gmail.com]
  3. * @copyright Crown Copyright 2016
  4. * @license Apache-2.0
  5. */
  6. import Operation from "../Operation";
  7. import OperationError from "../errors/OperationError";
  8. import bcrypt from "bcryptjs";
  9. /**
  10. * Bcrypt parse operation
  11. */
  12. class BcryptParse extends Operation {
  13. /**
  14. * BcryptParse constructor
  15. */
  16. constructor() {
  17. super();
  18. this.name = "Bcrypt parse";
  19. this.module = "Hashing";
  20. this.description = "Parses a bcrypt hash to determine the number of rounds used, the salt, and the password hash.";
  21. this.inputType = "string";
  22. this.outputType = "string";
  23. this.args = [];
  24. }
  25. /**
  26. * @param {string} input
  27. * @param {Object[]} args
  28. * @returns {string}
  29. */
  30. async run(input, args) {
  31. try {
  32. return `Rounds: ${bcrypt.getRounds(input)}
  33. Salt: ${bcrypt.getSalt(input)}
  34. Password hash: ${input.split(bcrypt.getSalt(input))[1]}
  35. Full hash: ${input}`;
  36. } catch (err) {
  37. throw new OperationError("Error: " + err.toString());
  38. }
  39. }
  40. }
  41. export default BcryptParse;