1 import { type FormikErrors } from 'formik';
2 import { c } from 'ttag';
4 import type { PasswordCredentials } from '@proton/pass/lib/auth/password';
5 import type { Maybe } from '@proton/pass/types';
6 import { BRAND_NAME } from '@proton/shared/lib/constants';
8 const validatePassword =
9 (errorMessage: string) =>
10 (values: PasswordCredentials): FormikErrors<PasswordCredentials> =>
11 values.password.length > 0 ? {} : { password: errorMessage };
13 export const validateCurrentPassword = validatePassword(c('Warning').t`${BRAND_NAME} password is required`);
14 export const validateExtraPassword = validatePassword(c('Warning').t`Extra password is required`);
16 export const validateNewExtraPassword = (password: string, previous?: string): Maybe<string> => {
17 if (password.length === 0) return c('Warning').t`Extra password cannot be empty`;
18 if (!previous && password.length < 8) return c('Warning').t`Extra password should have at least 8 characters`;
19 if (previous && password !== previous) return c('Warning').t`Passwords do not match`;