26 lines
744 B
TypeScript
26 lines
744 B
TypeScript
import { PasswordHash } from '../value-objects/PasswordHash';
|
|
|
|
/**
|
|
* Domain Service: PasswordHashingService
|
|
*
|
|
* Service for password hashing and verification.
|
|
*/
|
|
export interface PasswordHashingService {
|
|
hash(plain: string): Promise<string>;
|
|
verify(plain: string, hash: string): Promise<boolean>;
|
|
}
|
|
|
|
/**
|
|
* Implementation using bcrypt via PasswordHash VO.
|
|
*/
|
|
export class PasswordHashingService implements PasswordHashingService {
|
|
async hash(plain: string): Promise<string> {
|
|
const passwordHash = await PasswordHash.create(plain);
|
|
return passwordHash.value;
|
|
}
|
|
|
|
async verify(plain: string, hash: string): Promise<boolean> {
|
|
const passwordHash = PasswordHash.fromHash(hash);
|
|
return passwordHash.verify(plain);
|
|
}
|
|
} |