refactor
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
aovantsev
2025-10-10 19:56:06 +03:00
parent f081c9d947
commit 73ed514a34
30 changed files with 1728 additions and 1020 deletions

View File

@@ -0,0 +1,29 @@
package security
import "golang.org/x/crypto/bcrypt"
// PasswordService interface defines the contract for password operations
type PasswordService interface {
HashPassword(password string) (string, error)
CheckPasswordHash(password, hash string) bool
}
// PasswordServiceImpl implements PasswordService using bcrypt
type PasswordServiceImpl struct{}
// NewPasswordService creates a new password service
func NewPasswordService() PasswordService {
return &PasswordServiceImpl{}
}
// HashPassword hashes a password using bcrypt
func (p *PasswordServiceImpl) HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
return string(bytes), err
}
// CheckPasswordHash compares a password with its hash
func (p *PasswordServiceImpl) CheckPasswordHash(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}