auth
This commit is contained in:
@@ -62,8 +62,12 @@ export class LoginWithEmailUseCase {
|
||||
} as LoginWithEmailApplicationError);
|
||||
}
|
||||
|
||||
const passwordHash = await this.hashPassword(input.password, user.salt);
|
||||
if (passwordHash !== user.passwordHash) {
|
||||
// Verify password using PasswordHash value object
|
||||
const { PasswordHash } = await import('@core/identity/domain/value-objects/PasswordHash');
|
||||
const storedPasswordHash = PasswordHash.fromHash(user.passwordHash);
|
||||
const isValid = await storedPasswordHash.verify(input.password);
|
||||
|
||||
if (!isValid) {
|
||||
return Result.err({
|
||||
code: 'INVALID_CREDENTIALS',
|
||||
details: { message: 'Invalid email or password' },
|
||||
@@ -117,23 +121,4 @@ export class LoginWithEmailUseCase {
|
||||
}
|
||||
}
|
||||
|
||||
private async hashPassword(password: string, salt: string): Promise<string> {
|
||||
// Simple hash for demo - in production, use bcrypt or argon2
|
||||
const data = password + salt;
|
||||
if (typeof crypto !== 'undefined' && crypto.subtle) {
|
||||
const encoder = new TextEncoder();
|
||||
const dataBuffer = encoder.encode(data);
|
||||
const hashBuffer = await crypto.subtle.digest('SHA-256', dataBuffer);
|
||||
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
// Fallback for environments without crypto.subtle
|
||||
let hash = 0;
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const char = data.charCodeAt(i);
|
||||
hash = ((hash << 5) - hash) + char;
|
||||
hash = hash & hash;
|
||||
}
|
||||
return Math.abs(hash).toString(16).padStart(16, '0');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user