import bcrypt from 'bcrypt'; import type { ValueObject } from '@core/shared/domain/ValueObject'; export interface PasswordHashProps { value: string; } /** * Value Object: PasswordHash * * Wraps a bcrypt-hashed password string and provides verification. */ export class PasswordHash implements ValueObject { public readonly props: PasswordHashProps; private constructor(value: string) { this.props = { value }; } static async create(plain: string): Promise { const saltRounds = 12; const hash = await bcrypt.hash(plain, saltRounds); return new PasswordHash(hash); } static fromHash(hash: string): PasswordHash { return new PasswordHash(hash); } get value(): string { return this.props.value; } async verify(plain: string): Promise { return bcrypt.compare(plain, this.props.value); } equals(other: ValueObject): boolean { return this.props.value === other.props.value; } }