pwhash.js 567 B

1234567891011121314151617181920
  1. var sodium = require('sodium').api;
  2. process.stdout.write('Password: ');
  3. process.stdin.resume();
  4. process.stdin.setEncoding('utf8');
  5. process.stdin.on('data', function (input) {
  6. var password = Buffer.from('a password', 'utf8');
  7. var inPass = Buffer.from(input.trim(), 'utf8');
  8. var hash = sodium.crypto_pwhash_str(
  9. password,
  10. sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE,
  11. sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE);
  12. var isValid = sodium.crypto_pwhash_str_verify(hash, inPass);
  13. console.log(isValid ? 'Correct.' : 'Incorrect.');
  14. process.exit();
  15. });