Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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))
);
};