Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add empty field sanity check to login (#771)
Leendert de Borstb9c0f23e4570
diff --git a/mobile-app/app/login.tsx b/mobile-app/app/login.tsxindex 3ec3c31dc..e621edd14 100644--- a/mobile-app/app/login.tsx+++ b/mobile-app/app/login.tsx@@ -5,7 +5,6 @@ import { Buffer } from 'buffer';import { router } from 'expo-router';import AsyncStorage from '@react-native-async-storage/async-storage';import { useFocusEffect } from '@react-navigation/native';-import { ThemedView } from '@/components/ThemedView';import { useDb } from '@/context/DbContext';import { useAuth } from '@/context/AuthContext';@@ -210,16 +209,21 @@ export default function LoginScreen() {setIsLoading(true);setError(null);+ // Sanity check: if username or password is empty, return+ if (!credentials.username || !credentials.password) {+ setError('Username and password are required');+ setIsLoading(false);+ return;+ }+setLoginStatus('Logging in');try {- console.log('handleSubmit');authContext.clearGlobalMessage();const loginResponse = await srpUtil.initiateLogin(credentials.username);- console.log('loginResponse', loginResponse);-+ // Use requestAnimationFrame to ensure UI updates are smoothconst passwordHash = await EncryptionUtility.deriveKeyFromPassword(credentials.password,loginResponse.salt,@@ -227,13 +231,9 @@ export default function LoginScreen() {loginResponse.encryptionSettings);- console.log('passwordHash', passwordHash);-const passwordHashString = Buffer.from(passwordHash).toString('hex').toUpperCase();const passwordHashBase64 = Buffer.from(passwordHash).toString('base64');- console.log('passwordHashString', passwordHashString);-setLoginStatus('Validating credentials');const validationResponse = await srpUtil.validateLogin(credentials.username,@@ -242,8 +242,6 @@ export default function LoginScreen() {loginResponse);- console.log('validationResponse', validationResponse);-if (validationResponse.requiresTwoFactor) {setLoginResponse(loginResponse);setPasswordHashString(passwordHashString);@@ -258,15 +256,11 @@ export default function LoginScreen() {throw new Error('Login failed -- no token returned');}- console.log('validationResponse.token', validationResponse.token);-setLoginStatus('Syncing vault');const vaultResponseJson = await webApi.authFetch<any>('Vault', { method: 'GET', headers: {'Authorization': `Bearer ${validationResponse.token.token}`} });- console.log('vaultResponseJson', vaultResponseJson);-const vaultError = webApi.validateVaultResponse(vaultResponseJson);if (vaultError) {console.error('vaultError', vaultError);@@ -276,13 +270,10 @@ export default function LoginScreen() {return;}- console.log('vaultResponseJson', vaultResponseJson);-await authContext.setAuthTokens(credentials.username, validationResponse.token.token, validationResponse.token.refreshToken);await dbContext.initializeDatabase(vaultResponseJson, passwordHashBase64);await authContext.login();- console.log('logged in');router.replace('/(tabs)');setIsLoading(false);diff --git a/mobile-app/types/react-native-argon2.d.ts b/mobile-app/types/react-native-argon2.d.tsindex 2957bc8d8..bfdd0084a 100644--- a/mobile-app/types/react-native-argon2.d.ts+++ b/mobile-app/types/react-native-argon2.d.ts@@ -19,4 +19,4 @@ declare module 'react-native-argon2' {): Promise<Argon2Result>;export default argon2;-}\ No newline at end of file+}diff --git a/mobile-app/utils/SrpUtility.tsx b/mobile-app/utils/SrpUtility.tsxindex c6b0ea15c..904a6806f 100644--- a/mobile-app/utils/SrpUtility.tsx+++ b/mobile-app/utils/SrpUtility.tsx@@ -17,7 +17,6 @@ export class SrpUtility {*/public async initiateLogin(username: string): Promise<LoginResponse> {try {- console.log('initiateLogin');const response = await this.webApiService.rawFetch('Auth/login', {method: 'POST',headers: {@@ -26,8 +25,6 @@ export class SrpUtility {body: JSON.stringify({ username: username.toLowerCase().trim() }),});- console.log('initiateLogin response', response);-if (response.status === 400) {const badRequestResponse = await response.json() as BadRequestResponse;throw new ApiAuthError(badRequestResponse.title);@@ -53,17 +50,12 @@ export class SrpUtility {loginResponse: LoginResponse): Promise<ValidateLoginResponse> {try {- console.log('validateLogin');// Generate client ephemeralconst clientEphemeral = srp.generateEphemeral();- console.log('clientEphemeral', clientEphemeral);-// Derive private keyconst privateKey = srp.derivePrivateKey(loginResponse.salt, username, passwordHash);- console.log('privateKey', privateKey);-// Derive sessionconst sessionProof = srp.deriveSession(clientEphemeral.secret,@@ -73,8 +65,6 @@ export class SrpUtility {privateKey);- console.log('sessionProof', sessionProof);-const response = await this.webApiService.rawFetch('Auth/validate', {method: 'POST',headers: {@@ -160,4 +150,4 @@ export class SrpUtility {throw new ApiAuthError('Could not reach AliasVault server. Please try again later or contact support if the problem persists.');}}-}\ No newline at end of file+}