bcrypt

package
v2.294.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 2 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:

  • 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

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

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

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.

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 bcrypt.CompareHashAndPassword. It returns nil if the hash matches, otherwise it returns an error from the bcrypt package.

Jump to

Keyboard shortcuts

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