password

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package password hashes and verifies user passwords with the standard-library PBKDF2 implementation. Encoded hashes carry their parameters so applications can increase work over time without invalidating existing credentials.

Index

Constants

View Source
const (
	DefaultIterations = 600_000
)

Variables

View Source
var ErrInvalidHash = errors.New("invalid password hash")

Functions

This section is empty.

Types

type Hasher

type Hasher struct {
	// Iterations controls newly created hashes. Nonpositive values use the
	// default; Hash rejects values above 10,000,000, the verification limit.
	Iterations int
}

func New

func New() Hasher

func (Hasher) DummyVerify

func (hasher Hasher) DummyVerify(plain string)

DummyVerify performs equivalent expensive work for unknown-user login paths, reducing the usefulness of account-enumeration timing differences.

func (Hasher) Hash

func (hasher Hasher) Hash(plain string) (string, error)

func (Hasher) NeedsRehash

func (hasher Hasher) NeedsRehash(encoded string) bool

func (Hasher) Verify

func (hasher Hasher) Verify(encoded, plain string) (bool, error)

func (Hasher) VerifyCurrent added in v0.8.0

func (hasher Hasher) VerifyCurrent(encoded, plain string) (bool, error)

VerifyCurrent verifies an encoded password and, on mismatch, pads hashes created with an older policy to the current iteration budget. Login handlers should use this method so a failed attempt cannot identify accounts that are still awaiting transparent rehashing.

Jump to

Keyboard shortcuts

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