auth
This commit is contained in:
@@ -84,9 +84,9 @@ export class SignupWithEmailUseCase {
|
||||
}
|
||||
|
||||
try {
|
||||
// Hash password (simple hash for demo - in production use bcrypt)
|
||||
const salt = this.generateSalt();
|
||||
const passwordHash = await this.hashPassword(input.password, salt);
|
||||
// Hash password using PasswordHash value object
|
||||
const { PasswordHash } = await import('@core/identity/domain/value-objects/PasswordHash');
|
||||
const passwordHash = await PasswordHash.create(input.password);
|
||||
|
||||
// Create user
|
||||
const userId = this.generateUserId();
|
||||
@@ -95,8 +95,7 @@ export class SignupWithEmailUseCase {
|
||||
id: userId,
|
||||
email: input.email.toLowerCase().trim(),
|
||||
displayName: input.displayName.trim(),
|
||||
passwordHash,
|
||||
salt,
|
||||
passwordHash: passwordHash.value,
|
||||
createdAt,
|
||||
};
|
||||
|
||||
@@ -142,38 +141,6 @@ export class SignupWithEmailUseCase {
|
||||
}
|
||||
}
|
||||
|
||||
private generateSalt(): string {
|
||||
const array = new Uint8Array(16);
|
||||
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
||||
crypto.getRandomValues(array);
|
||||
} else {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
array[i] = Math.floor(Math.random() * 256);
|
||||
}
|
||||
}
|
||||
return Array.from(array, byte => byte.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
private generateUserId(): string {
|
||||
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
||||
return crypto.randomUUID();
|
||||
|
||||
Reference in New Issue
Block a user