crypto

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package crypto provides password hashing and comparison using bcrypt (golang.org/x/crypto/bcrypt).

Role in architecture:

  • Infrastructure utility: no business logic; used by auth or user flows that need to hash/compare passwords.

Responsibilities:

  • HashAndSalt: hash a plain password with bcrypt.MinCost; log and return empty string on error.
  • ComparePassword: return true if plain password matches the hash; log on error.

Constraints:

  • Single cost (MinCost); no configurable cost or salt in this package.
  • Depends on logger for error logging.

This package must NOT:

  • Store or retrieve passwords; only hash and compare.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComparePassword

func ComparePassword(hashedPassword string, plainPassword []byte) bool

ComparePassword returns true if plainPassword matches hashedPassword; logs and returns false on error. Returns false without calling bcrypt if hashedPassword is empty or too short to be a valid bcrypt hash, avoiding error logs for missing or invalid stored hashes.

func HashAndSalt

func HashAndSalt(plainPassword []byte) string

HashAndSalt hashes plainPassword with bcrypt (MinCost) and returns the hash string. On bcrypt error logs and returns "".

Types

This section is empty.

Jump to

Keyboard shortcuts

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