Documentation
¶
Overview ¶
Package password provides secret hashing and verification with hashes stored as a single PHC-formatted string.
Index ¶
- func Hash(secret string) (string, error)
- func NeedsRehash(encoded string) bool
- func Register(h Hasher)
- func SetDefault(h Hasher)
- func Verify(secret, encoded string) (bool, error)
- func VerifyEmpty(secret string)
- type Argon2idOption
- type BcryptOption
- type BlockSize
- type Cost
- type Hasher
- type KeyLength
- type LogN
- type Memory
- type Parallelism
- type SaltLength
- type ScryptOption
- type Time
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NeedsRehash ¶
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 ¶
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 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 ScryptOption ¶
type ScryptOption interface {
// contains filtered or unexported methods
}
ScryptOption is an option for the scrypt hasher.