Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Make username case insensitive during login for browser extension (#884)

Leendert de Borstf43bc402baa9
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/Login.tsx b/apps/browser-extension/src/entrypoints/popup/pages/Login.tsx
index 7a55e758b..1a48921fb 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/Login.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/Login.tsx
@@ -13,6 +13,7 @@ import { VaultResponse } from '@/utils/types/webapi/VaultResponse';
import { LoginResponse } from '@/utils/types/webapi/Login';
import LoginServerInfo from '@/entrypoints/popup/components/LoginServerInfo';
import { ApiAuthError } from '@/utils/types/errors/ApiAuthError';
+import ConversionUtility from '../utils/ConversionUtility';
/**
* Login page
@@ -66,7 +67,7 @@ const Login: React.FC = () => {
authContext.clearGlobalMessage();
// Use the srpUtil instance instead of the imported singleton
- const loginResponse = await srpUtil.initiateLogin(credentials.username);
+ const loginResponse = await srpUtil.initiateLogin(ConversionUtility.normalizeUsername(credentials.username));
// 1. Derive key from password using Argon2id
const passwordHash = await EncryptionUtility.deriveKeyFromPassword(
@@ -84,7 +85,7 @@ const Login: React.FC = () => {
// 2. Validate login with SRP protocol
const validationResponse = await srpUtil.validateLogin(
- credentials.username,
+ ConversionUtility.normalizeUsername(credentials.username),
passwordHashString,
rememberMe,
loginResponse
@@ -122,7 +123,7 @@ const Login: React.FC = () => {
}
// All is good. Store auth info which is required to make requests to the web API.
- await authContext.setAuthTokens(credentials.username, validationResponse.token.token, validationResponse.token.refreshToken);
+ await authContext.setAuthTokens(ConversionUtility.normalizeUsername(credentials.username), validationResponse.token.token, validationResponse.token.refreshToken);
// Initialize the SQLite context with the new vault data.
await dbContext.initializeDatabase(vaultResponseJson, passwordHashBase64);
@@ -164,7 +165,7 @@ const Login: React.FC = () => {
}
const validationResponse = await srpUtil.validateLogin2Fa(
- credentials.username,
+ ConversionUtility.normalizeUsername(credentials.username),
passwordHashString,
rememberMe,
loginResponse,
@@ -189,7 +190,7 @@ const Login: React.FC = () => {
}
// All is good. Store auth info which is required to make requests to the web API.
- await authContext.setAuthTokens(credentials.username, validationResponse.token.token, validationResponse.token.refreshToken);
+ await authContext.setAuthTokens(ConversionUtility.normalizeUsername(credentials.username), validationResponse.token.token, validationResponse.token.refreshToken);
// Initialize the SQLite context with the new vault data.
await dbContext.initializeDatabase(vaultResponseJson, passwordHashBase64);
diff --git a/apps/browser-extension/src/entrypoints/popup/utils/ConversionUtility.ts b/apps/browser-extension/src/entrypoints/popup/utils/ConversionUtility.ts
index 16480816b..5caa652a8 100644
--- a/apps/browser-extension/src/entrypoints/popup/utils/ConversionUtility.ts
+++ b/apps/browser-extension/src/entrypoints/popup/utils/ConversionUtility.ts
@@ -1,5 +1,7 @@
/**
* Utility class for conversion operations.
+ * TODO: make this a shared utility class in root /shared/ folder so we can reuse it between browser extension/mobile app
+ * and possibly WASM client.
*/
class ConversionUtility {
/**
@@ -49,6 +51,15 @@ class ConversionUtility {
return html;
}
}
+
+ /**
+ * Normalize a username by converting it to lowercase and trimming whitespace.
+ * @param username The username to normalize.
+ * @returns The normalized username.
+ */
+ public normalizeUsername(username: string): string {
+ return username.toLowerCase().trim();
+ }
}
export default new ConversionUtility();