1
0
mirror of https://github.com/volatiletech/authboss.git synced 2025-07-07 00:55:37 +02:00
Files
authboss/defaults/hasher.go
2023-10-28 20:57:02 +01:00

21 lines
374 B
Go

package defaults
import "golang.org/x/crypto/bcrypt"
type BCryptHasher struct {
cost int
}
func NewBCryptHasher(cost int) *BCryptHasher {
return &BCryptHasher{cost: cost}
}
func (h *BCryptHasher) GenerateHash(raw string) (string, error) {
hash, err := bcrypt.GenerateFromPassword([]byte(raw), h.cost)
if err != nil {
return "", err
}
return string(hash), nil
}