MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / verifyPasswordStrength

Function verifyPasswordStrength

packages/auth/src/password.ts:21–41  ·  view source on GitHub ↗
(
  password: string,
)

Source from the content-addressed store, hash-verified

19}
20
21export async function verifyPasswordStrength(
22 password: string,
23): Promise<boolean> {
24 if (password.length < 8 || password.length > 255) {
25 return false;
26 }
27 const hash = encodeHexLowerCase(sha1(new TextEncoder().encode(password)));
28 const hashPrefix = hash.slice(0, 5);
29 const response = await fetch(
30 `https://api.pwnedpasswords.com/range/${hashPrefix}`,
31 );
32 const data = await response.text();
33 const items = data.split('\n');
34 for (const item of items) {
35 const hashSuffix = item.slice(0, 35).toLowerCase();
36 if (hash === hashPrefix + hashSuffix) {
37 return false;
38 }
39 }
40 return true;
41}

Callers

nothing calls this directly

Calls 1

fetchFunction · 0.50

Tested by

no test coverage detected