Files
shared/backend/auth/password.go
T

21 lines
687 B
Go
Raw Normal View History

2026-08-04 15:17:15 +02:00
package auth
import "golang.org/x/crypto/bcrypt"
// BcryptCost is kept in one place so all services use the same password
// storage policy. Existing hashes remain valid when this value is raised.
const BcryptCost = 12
// HashPassword returns a bcrypt password hash suitable for storage.
func HashPassword(password string) (string, error) {
hash, err := bcrypt.GenerateFromPassword([]byte(password), BcryptCost)
if err != nil {
return "", err
}
return string(hash), nil
}
// VerifyPassword checks a plaintext password against a stored bcrypt hash.
func VerifyPassword(hash, password string) bool {
return bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) == nil
}