async_compare.js 919 B

12345678910111213141516171819202122232425262728
  1. const bcrypt = require('../bcrypt');
  2. (async () => {
  3. const start = Date.now();
  4. // genSalt
  5. const salt = await bcrypt.genSalt(10)
  6. console.log('salt: ' + salt);
  7. console.log('salt cb end: ' + (Date.now() - start) + 'ms');
  8. // hash
  9. const crypted = await bcrypt.hash('test', salt)
  10. console.log('crypted: ' + crypted);
  11. console.log('crypted cb end: ' + (Date.now() - start) + 'ms');
  12. console.log('rounds used from hash:', bcrypt.getRounds(crypted));
  13. // compare
  14. const res = await bcrypt.compare('test', crypted)
  15. console.log('compared true: ' + res);
  16. console.log('compared true cb end: ' + (Date.now() - start) + 'ms');
  17. // compare
  18. const res2 = await bcrypt.compare('bacon', crypted)
  19. console.log('compared false: ' + res2);
  20. console.log('compared false cb end: ' + (Date.now() - start) + 'ms');
  21. console.log('end: ' + (Date.now() - start) + 'ms');
  22. })();