Documentation
¶
Overview ¶
Package bcrypt provides bcrypt password hashing helpers for go-service.
This package wraps golang.org/x/crypto/bcrypt to provide a simple Signer that:
- hashes passwords using bcrypt.GenerateFromPassword with bcrypt.DefaultCost, and
- verifies password hashes using bcrypt.CompareHashAndPassword.
Start with `Signer` and `NewSigner`.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Module = di.Module( di.Constructor(NewSigner), )
Module wires the bcrypt subsystem into Fx/Dig.
It provides a constructor for `*Signer` via `NewSigner`, which can be used for password hashing and verification using bcrypt with the default cost.
This module does not require configuration.
Functions ¶
This section is empty.
Types ¶
type Signer ¶
type Signer struct{}
Signer hashes and verifies secrets using bcrypt.
This type is intended for password hashing and password hash verification. It is not a general-purpose message signing primitive.
Sign returns a bcrypt hash for the provided secret (typically a password). Verify checks whether the provided bcrypt hash matches the provided secret.
func NewSigner ¶
func NewSigner() *Signer
NewSigner constructs a bcrypt-based Signer intended for password hashing.
The returned Signer uses bcrypt.DefaultCost when hashing. If you need a different cost or more control over parameters, use golang.org/x/crypto/bcrypt directly.
func (*Signer) Sign ¶
Sign hashes msg using bcrypt with bcrypt.DefaultCost.
The returned value is a bcrypt hash suitable for storage. The input msg is typically a user password. Callers should store only the returned hash, never the plaintext secret.
This is a thin wrapper around bcrypt.GenerateFromPassword.