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:
1 parent
8460a078e3
commit
ff8cd5f0ec
16 files changed
+725
-88
No files matched your search
@@ -0,0 +1,29 @@
|
||||
package hashing
|
||||
|
||||
import (
|
||||
"RenewCMS/internal/domain/hash"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
const bcryptCost = 12
|
||||
|
||||
type BcryptHasher struct{}
|
||||
|
||||
func NewBcryptHasher() *BcryptHasher {
|
||||
return &BcryptHasher{}
|
||||
}
|
||||
|
||||
func (b *BcryptHasher) Hash(value string) (string, error) {
|
||||
hashed, err := bcrypt.GenerateFromPassword([]byte(value), bcryptCost)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(hashed), nil
|
||||
}
|
||||
|
||||
func (b *BcryptHasher) Compare(hashed string, value string) error {
|
||||
return bcrypt.CompareHashAndPassword([]byte(hashed), []byte(value))
|
||||
}
|
||||
|
||||
var _ hash.Hasher = &BcryptHasher{}
|
||||
Reference in new issue
Block a user