passwords

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package passwords provides bcrypt password hashing, email normalization, and breach-check via the HaveIBeenPwned k-anonymity API. Pure utility code, no DB or HTTP server dependency.

Index

Constants

View Source
const (
	// Cost is the bcrypt cost used by Hash.
	Cost = 12

	// FakeHash is a pre-computed bcrypt hash used for constant-time comparison
	// when a user is not found, to prevent timing-based user enumeration.
	FakeHash = "$2a$12$000000000000000000000uGLIFPqxVmExfOiAa9ebvJpSsQd/pxuu"
)

Variables

View Source
var (

	// HIBPEndpoint is overridable for tests.
	HIBPEndpoint = "https://api.pwnedpasswords.com/range/"
)

Functions

func CheckStrength

func CheckStrength(ctx context.Context, pw []byte) error

CheckStrength rejects passwords that are too short, too long, or known to be compromised per the HaveIBeenPwned breach database. Returns nil on the HIBP network error path (failing open) — only a confirmed breach hit blocks.

func Hash

func Hash(pw []byte) (string, error)

Hash returns a bcrypt hash of pw at the package Cost.

func NormalizeEmail

func NormalizeEmail(e string) (string, error)

NormalizeEmail lowercases, trims, and IDN-canonicalizes the domain. Returns the normalized form or an error if the address is malformed.

func Verify

func Verify(hash string, pw []byte) error

Verify reports whether pw matches the stored bcrypt hash.

func VerifyFake

func VerifyFake(pw []byte)

VerifyFake runs a bcrypt compare against FakeHash. Used to preserve constant-time response when a user lookup fails, avoiding user enumeration.

Types

This section is empty.

Jump to

Keyboard shortcuts

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