refactor to adapters
This commit is contained in:
26
core/identity/domain/services/PasswordHashingService.ts
Normal file
26
core/identity/domain/services/PasswordHashingService.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { PasswordHash } from '../value-objects/PasswordHash';
|
||||
|
||||
/**
|
||||
* Domain Service: PasswordHashingService
|
||||
*
|
||||
* Service for password hashing and verification.
|
||||
*/
|
||||
export interface IPasswordHashingService {
|
||||
hash(plain: string): Promise<string>;
|
||||
verify(plain: string, hash: string): Promise<boolean>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation using bcrypt via PasswordHash VO.
|
||||
*/
|
||||
export class PasswordHashingService implements IPasswordHashingService {
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user