index.js 462 B

1234567891011121314151617181920
  1. "use strict";
  2. // Des module.
  3. const des = require("unix-crypt-td-js");
  4. // Hash generation string.
  5. const itoa64 =
  6. "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  7. // Salt generation method.
  8. function getSalt() {
  9. return (
  10. itoa64[parseInt(Math.random() * 64)] + itoa64[parseInt(Math.random() * 64)]
  11. );
  12. }
  13. // Exporting old style.
  14. module.exports = (password, salt) => {
  15. return salt ? des(password, salt) : des(password, getSalt());
  16. };