AI Implementation feature(820): Project Scaffold and Platform Foundations (#1)
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { ApiError } from '../errors/api-error';
|
||||
import { ERROR_CODES } from '../errors/error-codes';
|
||||
|
||||
export function validatePassword(password: string, config: ConfigService): void {
|
||||
const minLen = config.get<number>('PASSWORD_MIN_LENGTH', 12);
|
||||
if (typeof password !== 'string' || password.length < minLen) {
|
||||
throw new ApiError(ERROR_CODES.WEAK_PASSWORD, `Password must be at least ${minLen} characters`, 400);
|
||||
}
|
||||
const requireMixed = config.get<boolean>('PASSWORD_REQUIRE_MIXED', true);
|
||||
if (requireMixed) {
|
||||
const hasUpper = /[A-Z]/.test(password);
|
||||
const hasLower = /[a-z]/.test(password);
|
||||
const hasDigit = /[0-9]/.test(password);
|
||||
const hasSymbol = /[^A-Za-z0-9]/.test(password);
|
||||
if (!(hasUpper && hasLower && hasDigit && hasSymbol)) {
|
||||
throw new ApiError(ERROR_CODES.WEAK_PASSWORD, 'Password must include upper, lower, digit, and symbol', 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user