From e2b4852e0ddaa91c704ef2a6ff7e317b05393c16 Mon Sep 17 00:00:00 2001 From: Jannis Heydemann Date: Wed, 29 Apr 2026 10:56:09 +0200 Subject: [PATCH 01/19] added password hashing --- account.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/account.js b/account.js index 2b7781a..b448104 100644 --- a/account.js +++ b/account.js @@ -22,7 +22,7 @@ function normalizeUser(user) { firstName: user.firstName || "", lastName: user.lastName || "", email: user.email || "", - password: user.password || "", + hashedPassword: user.hashedPassword || "", orders: Array.isArray(user.orders) ? user.orders : [], paymentMethods: Array.isArray(user.paymentMethods) ? user.paymentMethods : [] }; @@ -70,7 +70,14 @@ if (currentUser && currentUser.email) { } } -function registerUser() { +async function hashMessage(message) { + const msgBuffer = new TextEncoder().encode(message); // Encode as UTF-8 + const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer); // Hash + const hashArray = Array.from(new Uint8Array(hashBuffer)); // Convert to bytes + return hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); // Hex string +} + +async function registerUser() { const firstName = document.getElementById("reg-firstname")?.value.trim() || ""; const lastName = document.getElementById("reg-lastname")?.value.trim() || ""; const email = (document.getElementById("reg-email")?.value.trim() || "").toLowerCase(); @@ -92,11 +99,13 @@ function registerUser() { return; } + const hashedPassword = await hashMessage(password); + const newUser = { firstName, lastName, email, - password, + hashedPassword, orders: [], paymentMethods: [] }; @@ -113,12 +122,13 @@ function registerUser() { openAccountDashboard(); } -function loginUser() { +async function loginUser() { const email = (document.getElementById("login-email")?.value.trim() || "").toLowerCase(); const password = document.getElementById("login-password")?.value || ""; + const hashedPassword = await hashMessage(password); const user = users.find( - (entry) => entry.email.toLowerCase() === email && entry.password === password + (entry) => entry.email.toLowerCase() === email && entry.hashedPassword === hashedPassword ); if (!user) { -- 2.49.1 From 425c5d1900d5329a8125c62243fd30054c67af70 Mon Sep 17 00:00:00 2001 From: Jannis Heydemann Date: Wed, 29 Apr 2026 11:25:04 +0200 Subject: [PATCH 02/19] Added html hints to enable syntax highliting --- .gitignore | 1 + account.js | 4 ++-- cart.js | 12 ++++++------ checkout.js | 2 +- main.js | 8 ++++---- 5 files changed, 14 insertions(+), 13 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a5c0072 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +img/* \ No newline at end of file diff --git a/account.js b/account.js index b448104..06f44a1 100644 --- a/account.js +++ b/account.js @@ -152,7 +152,7 @@ function openAccountDashboard() { return; } - accountView.innerHTML = ` + accountView.innerHTML = /*html*/` + + diff --git a/src/components/SnacksView.astro b/src/components/SnacksView.astro index 683e6e8..d52a0d5 100644 --- a/src/components/SnacksView.astro +++ b/src/components/SnacksView.astro @@ -1,4 +1,4 @@ -