crypto

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 2 Imported by: 0

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