From 5c93a8de7a2c503a889cbc5ce6ad7b9909803e8a Mon Sep 17 00:00:00 2001 From: Jonas_Jones Date: Sun, 2 Mar 2025 20:48:20 +0100 Subject: [PATCH] fixed functions --- src/index.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/index.js b/src/index.js index 6592d05..41f8ca6 100644 --- a/src/index.js +++ b/src/index.js @@ -214,17 +214,14 @@ async function hashPassword(password) { const data = encoder.encode(password); const hashBuffer = await crypto.subtle.digest('SHA-256', data); - return bufferToHex(hashBuffer); + const hashArray = Array.from(new Uint8Array(hashBuffer)); + const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); + return hashHex; } -async function verifyPassword(password, storedHash) { - const hash = await hashPassword(password); - return hash === storedHash; -} - -function bufferToHex(buffer) { - const byteArray = new Uint8Array(buffer); - return Array.from(byteArray, byte => byte.toString(16).padStart(2, '0')).join(''); +async function verifyPassword(password, hash) { + const hashedPassword = await hashPassword(password); + return hashedPassword === hash; } function formatDate(date) {