refac: password and code hashing & checking go through a domain hasher interface used by the use cases instead of bcrypt in the user repository and the auth handler

This commit is contained in:
fsylvain committed 2026-09-23 19:29:20 +02:00
1 parent 8460a078e3
commit ff8cd5f0ec
16 files changed
+725 -88

No files matched your search

+16 -4
View File
@@ -1,6 +1,7 @@
package useCases
import (
"RenewCMS/internal/domain/hash"
"RenewCMS/internal/domain/user"
"time"
@@ -9,6 +10,7 @@ import (
type CreateUserUseCase struct {
userRepository user.Repository
hasher hash.Hasher
}
type CreateUserCommand struct {
@@ -17,20 +19,30 @@ type CreateUserCommand struct {
Email string
}
func NewCreateUserUseCase(userRepository user.Repository) *CreateUserUseCase {
return &CreateUserUseCase{userRepository}
func NewCreateUserUseCase(userRepository user.Repository, hasher hash.Hasher) *CreateUserUseCase {
return &CreateUserUseCase{userRepository, hasher}
}
func (g *CreateUserUseCase) CreateUser(createUser CreateUserCommand) (user.User, error) {
rawUuid := uuid.NewString()
hashedPassword, err := g.hasher.Hash(createUser.Password)
if err != nil {
return user.User{}, err
}
hashedVerificationCode, err := g.hasher.Hash(rawUuid)
if err != nil {
return user.User{}, err
}
createdUser, err := g.userRepository.Create(user.User{
Username: createUser.Username,
Password: createUser.Password,
Password: hashedPassword,
PasswordResetCode: "",
Email: createUser.Email,
IsVerified: false,
VerificationCode: rawUuid,
VerificationCode: hashedVerificationCode,
VerificationExpiration: time.Now().Add(2 * time.Hour),
})
if err != nil {