From c032e59247a66730c0c25707e70bad20f6b9f1f7 Mon Sep 17 00:00:00 2001 From: Bob Fanger Date: Mon, 19 Sep 2022 09:44:10 +0200 Subject: [PATCH] [docs] Improved security in code example (#6877) --- documentation/docs/06-form-actions.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/documentation/docs/06-form-actions.md b/documentation/docs/06-form-actions.md index d235852b483c..fcf1300a835b 100644 --- a/documentation/docs/06-form-actions.md +++ b/documentation/docs/06-form-actions.md @@ -148,12 +148,13 @@ export const actions = { const email = data.get('email'); const password = data.get('password'); - const user = await db.getUser(email); -+ if (!user) { ++ if (!email) { + return invalid(400, { email, missing: true }); + } -+ -+ if (user.password !== hash(password)) { + + const user = await db.getUser(email); + ++ if (!user || user.password !== hash(password)) { + return invalid(400, { email, incorrect: true }); + } @@ -173,11 +174,10 @@ export const actions = { /// file: src/routes/login/+page.svelte
- -+ {#if form?.missing}

No user found with this email

{/if} ++ {#if form?.missing}

The email field is required

{/if} ++ {#if form?.incorrect}

Invalid credentials!

{/if} + -- -+ {#if form?.incorrect}

Wrong password!

{/if}