Files
gochat/pkg/crypto/hash.go
T
2026-06-04 15:44:48 +08:00

19 lines
525 B
Go

package crypto
import (
"golang.org/x/crypto/bcrypt"
)
// HashPassword creates a bcrypt hash of the password.
// Reference: Chatwoot Devise bcrypt password hashing
func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
return string(bytes), err
}
// CheckPassword verifies a password against its hash
func CheckPassword(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}