How to use the jssha/src/sha1 function in jssha

To help you get started, we’ve selected a few jssha examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wKovacs64 / hibp / src / pwnedPassword.ts View on Github external
const pwnedPassword = (
  password: string,
  options: { baseUrl?: string; userAgent?: string } = {},
): Promise => {
  const sha1 = new JSSHA('SHA-1', 'TEXT');
  sha1.update(password);
  const hash = sha1.getHash('HEX', { outputUpper: true });
  const prefix = hash.slice(0, 5);
  const suffix = hash.slice(5);

  return (
    pwnedPasswordRange(prefix, options)
      // filter to matching suffix
      .then(arr => arr.filter(item => item.suffix === suffix))
      // return count if match, 0 if not
      .then(arr => (arr[0] ? arr[0].count : 0))
  );
};

jssha

jsSHA implements the complete Secure Hash Standard (SHA) family (SHA-1, SHA-224/256/384/512, SHA3-224/256/384/512, SHAKE128/256, cSHAKE128/256, and KMAC128/256) with HMAC

BSD-3-Clause
Latest version published 1 year ago

Package Health Score

73 / 100
Full package analysis

Popular jssha functions