22 lines
866 B
TypeScript
22 lines
866 B
TypeScript
/**
|
|
* In-Memory Password Hashing Service
|
|
*
|
|
* Provides basic password hashing and comparison for demo/development purposes.
|
|
* NOT FOR PRODUCTION USE - uses a simple string reversal as "hashing".
|
|
*/
|
|
|
|
import type { PasswordHashingService } from '@core/identity/domain/services/PasswordHashingService';
|
|
|
|
export class InMemoryPasswordHashingService implements PasswordHashingService {
|
|
async hash(plain: string): Promise<string> {
|
|
// In a real application, use a robust hashing library like bcrypt or Argon2.
|
|
// For demo, we'll just reverse the password and add a salt-like prefix.
|
|
const salt = 'demo_salt_';
|
|
return Promise.resolve(salt + plain.split('').reverse().join(''));
|
|
}
|
|
|
|
async verify(plain: string, hash: string): Promise<boolean> {
|
|
const hashedPlain = await this.hash(plain);
|
|
return Promise.resolve(hashedPlain === hash);
|
|
}
|
|
} |