Files
platform/src/servers/api/auth/validate-password.ts
T
2026-02-16 19:34:35 +00:00

24 lines
719 B
TypeScript

import * as errors from '@@/custom-errors';
export function validatePassword(password: string | undefined): void {
if (!password || password.length < 12) {
throw errors.BAD_REQUEST('Password must be at least 12 characters');
}
if (!/[a-z]/.test(password)) {
throw errors.BAD_REQUEST('Password must contain lowercase letters');
}
if (!/[A-Z]/.test(password)) {
throw errors.BAD_REQUEST('Password must contain uppercase letters');
}
if (!/[0-9]/.test(password)) {
throw errors.BAD_REQUEST('Password must contain numbers');
}
if (!/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(password)) {
throw errors.BAD_REQUEST('Password must contain special characters (!@#$%^&* etc.)');
}
}