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

@@ -5,7 +5,6 @@ import (
"RenewCMS/internal/infrastructure/persistence/mappers"
entity "RenewCMS/internal/infrastructure/persistence/models"
"golang.org/x/crypto/bcrypt"
"gorm.io/gorm"
)
@@ -28,14 +27,11 @@ func (u *UserRepository) Get(id uint32) (domainUser.User, error) {
}
func (u *UserRepository) Create(user domainUser.User) (domainUser.User, error) {
hashedPassword, _ := bcrypt.GenerateFromPassword([]byte(user.Password), 12)
hashedVerificationCode, _ := bcrypt.GenerateFromPassword([]byte(user.VerificationCode), 12)
creationResult := u.db.Create(&entity.User{
Username: user.Username,
Password: string(hashedPassword),
Password: user.Password,
Email: user.Email,
VerificationCode: string(hashedVerificationCode),
VerificationCode: user.VerificationCode,
VerificationExpiration: user.VerificationExpiration,
})
if creationResult.Error != nil {
@@ -108,8 +104,7 @@ func (u *UserRepository) UpdatePassword(userId uint32, password string) (domainU
return domainUser.User{}, err
}
hashedPassword, _ := bcrypt.GenerateFromPassword([]byte(password), 12)
localUser.Password = string(hashedPassword)
localUser.Password = password
err = u.db.Save(&localUser).Error
if err != nil {
return domainUser.User{}, err
@@ -125,8 +120,7 @@ func (u *UserRepository) UpdatePasswordResetCode(userId uint32, code string) (do
return domainUser.User{}, err
}
hashedCode, _ := bcrypt.GenerateFromPassword([]byte(code), 12)
localUser.PasswordResetCode = string(hashedCode)
localUser.PasswordResetCode = code
err = u.db.Save(&localUser).Error
if err != nil {
return domainUser.User{}, err