bcrypt

package
v2.679.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 4 Imported by: 0

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:

Start with Signer and NewSigner.

Index

Constants

View Source
const DefaultCost = bcrypt.DefaultCost

DefaultCost is the cost used by Sign.

Variables

Module wires the bcrypt subsystem into go.uber.org/fx/go.uber.org/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

func Cost added in v2.498.0

func Cost(hash []byte) (int, error)

Cost returns the hashing cost used to create the provided bcrypt hash.

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 golang.org/x/crypto/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

func (s *Signer) Sign(msg []byte) ([]byte, error)

Sign hashes msg using bcrypt with golang.org/x/crypto/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 golang.org/x/crypto/bcrypt.GenerateFromPassword.

func (*Signer) Verify

func (s *Signer) Verify(sig, msg []byte) error

Verify checks that sig is a valid bcrypt hash for msg.

This is a thin wrapper around golang.org/x/crypto/bcrypt.CompareHashAndPassword. It returns nil if the hash matches, otherwise it returns github.com/alexfalkowski/go-service/v2/crypto/errors.ErrInvalidMatch joined with the bcrypt package error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL