heritage-api/service/password-service.go

23 lines
525 B
Go
Raw Normal View History

2026-03-12 09:28:19 +00:00
package service
2026-03-13 08:35:54 +00:00
import (
"golang.org/x/crypto/bcrypt"
2026-03-12 09:28:19 +00:00
2026-03-13 08:35:54 +00:00
"github.com/sirupsen/logrus"
)
func PasswordHash(password string) (string, error) {
2026-03-12 09:28:19 +00:00
h, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
if err != nil {
2026-03-13 08:35:54 +00:00
logrus.WithFields(logrus.Fields{
"func": "PasswordHash",
}).Warnf("bcrypt.GenerateFromPassword: %v", err)
2026-03-12 09:28:19 +00:00
return "", err
}
return string(h), nil
}
2026-03-13 08:35:54 +00:00
func PasswordVerify(hash, password string) bool {
2026-03-12 09:28:19 +00:00
return bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) == nil
}