password

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Argon2DefaultSaltLength  = 16
	Argon2DefaultHashLength  = 32
	Argon2DefaultParallelism = 1
	Argon2DefaultMemory      = 1 << 14 // 16384 KiB (16 MiB)
	Argon2DefaultIterations  = 2
	Argon2MaxMemoryKiB       = 1 << 20 // 1048576 KiB (1 GiB)
	Argon2MinHashLength      = 16
	Argon2MaxHashLength      = 1024
	Argon2MaxIterations      = 1000
)
View Source
const (
	BCryptDefaultCost     = bcrypt.DefaultCost
	BCryptDefaultStrength = BCryptDefaultCost
)
View Source
const (
	Pbkdf2DefaultSaltLength = 16
	Pbkdf2DefaultIterations = 310000
	Pbkdf2DefaultKeyLength  = 32 // 256 bits
	Pbkdf2DefaultAlgorithm  = "PBKDF2WithHmacSHA256"
	Pbkdf2MaxIterations     = 5000000
	Pbkdf2MaxSaltLength     = 128
	Pbkdf2MaxHashLength     = 64
)
View Source
const (
	SCryptDefaultCpuCost     = 65536 // 2^16 (N)
	SCryptDefaultMemoryCost  = 8     // (r)
	SCryptDefaultParallelism = 1     // (p)
	SCryptDefaultKeyLength   = 32    // (dkLen)
	SCryptDefaultSaltLength  = 16
	SCryptMaxCpuCost         = 1 << 20 // 1048576
	SCryptMaxLn              = 20
	SCryptMaxMemoryCost      = 64
	SCryptMaxParallelism     = 64
	SCryptMaxNr              = 1 << 20 // 1048576
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Argon2PasswordEncoder added in v0.3.0

type Argon2PasswordEncoder struct {
	// contains filtered or unexported fields
}

Argon2PasswordEncoder implements [core.PasswordEncoder] using the Argon2 hashing algorithm (specifically Argon2id by default, adhering to RFC 9106 and the PHC string format).

func (*Argon2PasswordEncoder) Encode added in v0.3.0

func (this *Argon2PasswordEncoder) Encode(password []byte) ([]byte, error)

Encode implements [core.PasswordEncoder].

func (*Argon2PasswordEncoder) Matches added in v0.3.0

func (this *Argon2PasswordEncoder) Matches(password, encoded []byte) bool

Matches implements [core.PasswordEncoder].

func (Argon2PasswordEncoder) New added in v0.3.0

func (this Argon2PasswordEncoder) New(iterations, memory uint32, parallelism uint8, keyLength uint32, saltLength int) *Argon2PasswordEncoder

New constructs an Argon2PasswordEncoder with custom parameters.

func (Argon2PasswordEncoder) NewDefault added in v0.3.0

func (this Argon2PasswordEncoder) NewDefault() *Argon2PasswordEncoder

NewDefault constructs an Argon2PasswordEncoder with recommended defaults matching Spring Security 5.8+ defaults (iterations=2, memory=16384 KiB, parallelism=1, keyLength=32, saltLength=16).

type BCryptPasswordEncoder

type BCryptPasswordEncoder struct {
	// contains filtered or unexported fields
}

func (*BCryptPasswordEncoder) Encode

func (this *BCryptPasswordEncoder) Encode(password []byte) ([]byte, error)

Encode implements [core.PasswordEncoder].

func (*BCryptPasswordEncoder) Matches

func (this *BCryptPasswordEncoder) Matches(password, encoded []byte) bool

Matches implements [core.PasswordEncoder].

func (BCryptPasswordEncoder) New

func (this BCryptPasswordEncoder) New(strength int) *BCryptPasswordEncoder

func (BCryptPasswordEncoder) NewDefault added in v0.3.0

func (this BCryptPasswordEncoder) NewDefault() *BCryptPasswordEncoder

type BcryptPasswordEncoder added in v0.3.0

type BcryptPasswordEncoder = BCryptPasswordEncoder

type DelegatingPasswordEncoder

type DelegatingPasswordEncoder struct {
	// contains filtered or unexported fields
}

func (*DelegatingPasswordEncoder) Encode

func (this *DelegatingPasswordEncoder) Encode(password []byte) ([]byte, error)

Encode implements [core.PasswordEncoder].

func (*DelegatingPasswordEncoder) Matches

func (this *DelegatingPasswordEncoder) Matches(password, encoded []byte) bool

Matches implements [core.PasswordEncoder].

func (DelegatingPasswordEncoder) New

func (this DelegatingPasswordEncoder) New(idForEncode string, idToPasswordEncoder map[string]PasswordEncoder) *DelegatingPasswordEncoder

func (DelegatingPasswordEncoder) NewDefault added in v0.3.0

type NoOpPasswordEncoder

type NoOpPasswordEncoder struct{}

func (*NoOpPasswordEncoder) Encode

func (this *NoOpPasswordEncoder) Encode(password []byte) ([]byte, error)

Encode implements [core.PasswordEncoder].

func (*NoOpPasswordEncoder) Matches

func (this *NoOpPasswordEncoder) Matches(password, encoded []byte) bool

Matches implements [core.PasswordEncoder].

func (NoOpPasswordEncoder) New

type PBKDF2PasswordEncoder added in v0.3.0

type PBKDF2PasswordEncoder = Pbkdf2PasswordEncoder

type Pbkdf2PasswordEncoder added in v0.3.0

type Pbkdf2PasswordEncoder struct {
	// contains filtered or unexported fields
}

Pbkdf2PasswordEncoder implements [core.PasswordEncoder] using the PBKDF2 key derivation function. It defaults to PBKDF2 with HMAC-SHA256 and Hex encoding, compatible with Spring Security's Pbkdf2PasswordEncoder.

func (*Pbkdf2PasswordEncoder) Encode added in v0.3.0

func (this *Pbkdf2PasswordEncoder) Encode(password []byte) ([]byte, error)

Encode implements [core.PasswordEncoder].

func (*Pbkdf2PasswordEncoder) Matches added in v0.3.0

func (this *Pbkdf2PasswordEncoder) Matches(password, encoded []byte) bool

Matches implements [core.PasswordEncoder].

func (Pbkdf2PasswordEncoder) New added in v0.3.0

func (this Pbkdf2PasswordEncoder) New(secret string, saltLength, iterations, keyLength int, algorithm string) *Pbkdf2PasswordEncoder

New constructs a Pbkdf2PasswordEncoder with custom configuration.

func (Pbkdf2PasswordEncoder) NewDefault added in v0.3.0

func (this Pbkdf2PasswordEncoder) NewDefault() *Pbkdf2PasswordEncoder

NewDefault constructs a Pbkdf2PasswordEncoder with recommended defaults matching Spring Security 5.8+ (empty secret, saltLength=16, iterations=310000, keyLength=32, algorithm="PBKDF2WithHmacSHA256").

func (*Pbkdf2PasswordEncoder) SetEncodeHashAsBase64 added in v0.3.0

func (this *Pbkdf2PasswordEncoder) SetEncodeHashAsBase64(encodeHashAsBase64 bool) *Pbkdf2PasswordEncoder

SetEncodeHashAsBase64 sets whether the encoded password should be formatted in Base64 instead of Hex.

type SCryptPasswordEncoder added in v0.3.0

type SCryptPasswordEncoder struct {
	// contains filtered or unexported fields
}

SCryptPasswordEncoder implements [core.PasswordEncoder] using the SCrypt key derivation function. It formats and parses hashes compatible with Spring Security's SCrypt format ($<hex_params>$<salt>$<derived>).

func (*SCryptPasswordEncoder) Encode added in v0.3.0

func (this *SCryptPasswordEncoder) Encode(password []byte) ([]byte, error)

Encode implements [core.PasswordEncoder].

func (*SCryptPasswordEncoder) Matches added in v0.3.0

func (this *SCryptPasswordEncoder) Matches(password, encoded []byte) bool

Matches implements [core.PasswordEncoder].

func (SCryptPasswordEncoder) New added in v0.3.0

func (this SCryptPasswordEncoder) New(cpuCost, memoryCost, parallelism, keyLength, saltLength int) *SCryptPasswordEncoder

New constructs an SCryptPasswordEncoder with custom parameters.

func (SCryptPasswordEncoder) NewDefault added in v0.3.0

func (this SCryptPasswordEncoder) NewDefault() *SCryptPasswordEncoder

NewDefault constructs an SCryptPasswordEncoder with recommended defaults matching Spring Security 5.8+ defaults (cpuCost=65536, memoryCost=8, parallelism=1, keyLength=32, saltLength=16).

type ScryptPasswordEncoder added in v0.3.0

type ScryptPasswordEncoder = SCryptPasswordEncoder

Jump to

Keyboard shortcuts

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