password

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package password provides secret hashing and verification with hashes stored as a single PHC-formatted string.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(secret string) (string, error)

Hash returns the PHC encoded hash of the secret using the default Hasher.

func NeedsRehash

func NeedsRehash(encoded string) bool

NeedsRehash reports whether encoded was produced with an algorithm or parameters different from the default Hasher's configuration.

func Register

func Register(h Hasher)

Register adds an algorithm to the verification registry so Verify can dispatch on its encoded name prefix.

func SetDefault

func SetDefault(h Hasher)

SetDefault replaces the process-wide default Hasher used by Hash, VerifyEmpty and NeedsRehash, and registers it for verification.

func Verify

func Verify(secret, encoded string) (bool, error)

Verify reports whether secret matches the encoded hash, dispatching on the hash algorithm name prefix.

func VerifyEmpty

func VerifyEmpty(secret string)

VerifyEmpty performs the same amount of work as Verify against a hash that does not exist using the default Hasher, always failing.

Types

type Argon2idOption

type Argon2idOption interface {
	// contains filtered or unexported methods
}

Argon2idOption is an option for the argon2id hasher.

type BcryptOption

type BcryptOption interface {
	// contains filtered or unexported methods
}

BcryptOption is an option for the bcrypt hasher.

type BlockSize

type BlockSize int

BlockSize is the scrypt block size parameter r.

type Cost

type Cost int

Cost is the bcrypt cost.

type Hasher

type Hasher interface {
	// Name is the PHC algorithm identifier.
	Name() string
	// Hash returns the PHC encoded hash of the secret using the configured
	// parameters and a fresh random salt.
	Hash(secret string) (string, error)
	// Verify reports in constant time whether secret matches the encoded
	// hash.
	Verify(secret, encoded string) (bool, error)
	// VerifyEmpty performs the same amount of work as Verify against a hash
	// that does not exist.
	VerifyEmpty(secret string)
	// NeedsRehash reports whether encoded was produced with an algorithm or
	// parameters different from this hasher's configuration.
	NeedsRehash(encoded string) bool
}

Hasher hashes and verifies secrets in a PHC-formatted string.

func NewArgon2id

func NewArgon2id(opts ...Argon2idOption) Hasher

NewArgon2id returns a Hasher using argon2id with OWASP recommended defaults: 19 MiB memory, 2 passes, 1 thread, 16 byte salt, 32 byte key.

func NewBcrypt

func NewBcrypt(opts ...BcryptOption) Hasher

NewBcrypt returns a Hasher using bcrypt with the default cost 10.

func NewScrypt

func NewScrypt(opts ...ScryptOption) Hasher

NewScrypt returns a Hasher using scrypt with OWASP recommended defaults: N=2^17, r=8, p=1, 16 byte salt, 32 byte key.

type KeyLength

type KeyLength uint32

KeyLength is the derived key length in bytes.

type LogN

type LogN int

LogN is the base 2 logarithm of the scrypt CPU/memory cost parameter N.

type Memory

type Memory uint32

Memory is the argon2id memory cost in KiB.

type Parallelism

type Parallelism uint8

Parallelism is the argon2id number of threads.

type SaltLength

type SaltLength uint32

SaltLength is the salt length in bytes.

type ScryptOption

type ScryptOption interface {
	// contains filtered or unexported methods
}

ScryptOption is an option for the scrypt hasher.

type Time

type Time uint32

Time is the argon2id number of passes.

Jump to

Keyboard shortcuts

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