forked from wrenn/wrenn
Moves 12 packages from internal/ to pkg/ (config, id, validate, events, db, auth, lifecycle, scheduler, channels, audit, service) so they can be imported by the enterprise repo as a Go module dependency. Introduces pkg/cpextension (shared Extension interface + ServerContext) and pkg/cpserver (Run() entrypoint with functional options) so the enterprise main.go can call cpserver.Run(cpserver.WithExtensions(...)) without duplicating the 20-step server bootstrap. Adds db/migrations/embed.go for go:embed access to OSS SQL migrations from the enterprise module. cmd/control-plane/main.go is reduced to a 10-line wrapper around cpserver.Run.
17 lines
480 B
Go
17 lines
480 B
Go
package auth
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
const bcryptCost = 12
|
|
|
|
// HashPassword returns the bcrypt hash of a plaintext password.
|
|
func HashPassword(plaintext string) (string, error) {
|
|
b, err := bcrypt.GenerateFromPassword([]byte(plaintext), bcryptCost)
|
|
return string(b), err
|
|
}
|
|
|
|
// CheckPassword returns nil if plaintext matches the stored hash.
|
|
func CheckPassword(hash, plaintext string) error {
|
|
return bcrypt.CompareHashAndPassword([]byte(hash), []byte(plaintext))
|
|
}
|