|
1 | 1 | import { isIP } from 'net'; |
2 | | -import { createHash, randomBytes } from 'crypto'; |
| 2 | +import { randomBytes } from 'crypto'; |
3 | 3 | import { resolve } from 'path'; |
4 | 4 | import { readFile } from 'fs/promises'; |
5 | 5 |
|
@@ -41,10 +41,12 @@ export async function isDisposableEmail(email) { |
41 | 41 | export async function checkPasswordBreach(password) { |
42 | 42 | if (!password || password.length < 6) return { breached: false }; |
43 | 43 | try { |
44 | | - const input = String.fromCharCode(...Buffer.from(password, 'utf-8')); |
45 | | - const hash = createHash('sha256').update(input, 'binary').digest('hex').toUpperCase(); |
46 | | - const prefix = hash.slice(0, 5); |
47 | | - const suffix = hash.slice(5); |
| 44 | + const encoded = new TextEncoder().encode(password); |
| 45 | + const buf = await globalThis.crypto.subtle.digest('SHA-256', encoded); |
| 46 | + const view = new Uint8Array(buf); |
| 47 | + const hex = Array.from(view).map(b => b.toString(16).padStart(2, '0')).join('').toUpperCase(); |
| 48 | + const prefix = hex.slice(0, 5); |
| 49 | + const suffix = hex.slice(5); |
48 | 50 | const res = await fetchWithTimeout(`https://api.pwnedpasswords.com/range/${prefix}`, {}, 5000); |
49 | 51 | const text = await res.text(); |
50 | 52 | const found = text.split('\n').some(line => { |
|
0 commit comments