Files
apocapoc-api/internal/infrastructure/crypto/bcrypt_hasher.go
T
david 4c8f3022f0
CI/CD Pipeline / Test (push) Has been cancelled
CI/CD Pipeline / Lint (push) Has been cancelled
CI/CD Pipeline / Build and Push Docker Image (push) Has been cancelled
Refactor password hashing to follow DIP and improve CI/CD
- Create PasswordHasher interface in domain layer
- Implement BcryptHasher in infrastructure layer
- Update RegisterUserHandler and LoginUserHandler to use interface
- Remove bcrypt dependency from application layer
- Update main.go and integration tests with dependency injection
- Enhance CI/CD workflow with test and lint jobs
- Add code coverage check (minimum 50%)
- Add go vet and gofmt validation
- Configure build job to depend on test and lint passing
- Update GitHub Actions to latest versions (v4→v5)

This achieves 100% SOLID compliance (DIP) and ensures Clean Architecture
by removing external library dependencies from application/domain layers.
2025-11-26 21:39:52 +01:00

26 lines
581 B
Go

package crypto
import (
"apocapoc-api/internal/domain/services"
"golang.org/x/crypto/bcrypt"
)
type BcryptHasher struct{}
func NewBcryptHasher() services.PasswordHasher {
return &BcryptHasher{}
}
func (b *BcryptHasher) Hash(password string) (string, error) {
hashedBytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
if err != nil {
return "", err
}
return string(hashedBytes), nil
}
func (b *BcryptHasher) Compare(hashedPassword, password string) error {
return bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password))
}