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

@@ -0,0 +1,28 @@
package useCases
import (
"RenewCMS/internal/domain/hash"
"RenewCMS/internal/domain/user"
)
type AuthenticateUserUseCase struct {
userRepository user.Repository
hasher hash.Hasher
}
func NewAuthenticateUserUseCase(userRepository user.Repository, hasher hash.Hasher) *AuthenticateUserUseCase {
return &AuthenticateUserUseCase{userRepository, hasher}
}
func (a *AuthenticateUserUseCase) Authenticate(username string, password string) (user.User, error) {
dbUser, err := a.userRepository.GetByUsername(username)
if err != nil {
return user.User{}, err
}
if err := a.hasher.Compare(dbUser.Password, password); err != nil {
return user.User{}, user.ErrInvalidCredentials
}
return dbUser, nil
}