From 73cf615d67ebad575beff6e278cedb2687cee45f Mon Sep 17 00:00:00 2001 From: Bruno Bernardino Date: Sat, 26 Aug 2023 10:05:31 +0100 Subject: [PATCH] Force email lowercase on signup and login. --- public/ts/utils.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/public/ts/utils.ts b/public/ts/utils.ts index a76e71d..c662231 100644 --- a/public/ts/utils.ts +++ b/public/ts/utils.ts @@ -176,8 +176,10 @@ export async function validateLogin(email: string, password: string) { const passwordKey = await Encryption.getAuthKey(password); + const lowercaseEmail = (email || '').toLocaleLowerCase().trim(); + const body: { email: string } = { - email, + email: lowercaseEmail, }; const response = await fetch('/api/session', { method: 'POST', headers, body: JSON.stringify(body) }); @@ -235,7 +237,7 @@ export async function validateLogin(email: string, password: string) { const session: StoredSession = { sessionId, userId: user.id, - email, + email: lowercaseEmail, keyPair, }; @@ -261,8 +263,10 @@ export async function createAccount(email: string, password: string) { const keyPair = await Encryption.generateKeyPair(); const encryptedKeyPair = await Encryption.encrypt(JSON.stringify(keyPair), passwordKey); + const lowercaseEmail = (email || '').toLocaleLowerCase().trim(); + const body: { email: string; encrypted_key_pair: string } = { - email, + email: lowercaseEmail, encrypted_key_pair: encryptedKeyPair, }; @@ -276,7 +280,7 @@ export async function createAccount(email: string, password: string) { const session: StoredSession = { sessionId, userId: user.id, - email, + email: lowercaseEmail, keyPair, };