Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func RandomSalt ¶
RandomSalt returns a random salt of the given length.
Types ¶
type Argon2Password ¶
type Argon2Password struct { Time uint32 Memory uint32 Parallelism uint8 KeyLen uint32 Salt []byte // contains filtered or unexported fields }
func (*Argon2Password) Password ¶
func (p *Argon2Password) Password() (string, error)
Password generates a password hash.
func (*Argon2Password) Verify ¶
func (p *Argon2Password) Verify(plaintext string) error
Verify verifies the plaintext with the password hash.
type Argon2PasswordOption ¶
type Argon2PasswordOption func(*Argon2Password)
Argon2PasswordOption is a function that can be used to configure a Argon2Password.
func Argon2KeyLen ¶
func Argon2KeyLen(keyLen uint32) Argon2PasswordOption
Argon2KeyLen sets the `keylen` parameter for Argon2 algorithm, the desired length of the returned hash. Recommended value is 32.
func Argon2Memory ¶
func Argon2Memory(memory uint32) Argon2PasswordOption
Argon2Memory sets the `memory` parameter for Argon2 algorithm, which is the memory cost, in KiB. Recommended value is 64 * 1024, i.e. 64 MB.
func Argon2Parallelism ¶
func Argon2Parallelism(parallelism uint8) Argon2PasswordOption
Argon2Parallelism sets the `parallelism` parameter for Argon2 algorithm, which is the number of threads. Recommended value is 1.
func Argon2Salt ¶
func Argon2Salt(salt []byte) Argon2PasswordOption
Argon2Salt sets the `salt` parameter for Argon2 algorithm. Recommended value is a 16 bytes random secret.
func Argon2Time ¶
func Argon2Time(time uint32) Argon2PasswordOption
Argon2Time sets the `time` parameter for Argon2 algorithm, which is the number of iterations. Recommended value is 2.
type BcryptPassword ¶ added in v1.1.0
type BcryptPassword struct { Cost int // contains filtered or unexported fields }
func (*BcryptPassword) Password ¶ added in v1.1.0
func (p *BcryptPassword) Password() (string, error)
func (*BcryptPassword) Verify ¶ added in v1.1.0
func (p *BcryptPassword) Verify(plaintext string) error
Verify verifies the plaintext with the password hash.
type BcryptPasswordOption ¶ added in v1.1.0
type BcryptPasswordOption func(*BcryptPassword)
BcryptPasswordOption is a function that can be used to configure a BcryptPassword.
func BcryptCost ¶ added in v1.1.0
func BcryptCost(cost int) BcryptPasswordOption
type Password ¶
type Password interface { // Verify compares the plaintext with the hashed password. Verify(plaintext string) error }
Password is a hashed password who can verify a plaintext password.
func NewArgon2idPassword ¶
NewArgon2idPassword loads a password hash and can be used to verify a plaintext.
func NewBcryptPassword ¶ added in v1.1.0
type Plaintext ¶
Plaintext is a plaintext password and can be used to generate a password hash. Typically the hash will be stored in a database.
func NewArgon2idPlaintext ¶
func NewArgon2idPlaintext(plaintext string, opts ...Argon2PasswordOption) (Plaintext, error)
NewArgon2idPlaintext creates a plaintext password that can be hashed with Argon2id.
func NewBcryptPlaintext ¶ added in v1.1.0
func NewBcryptPlaintext(plaintext string, opts ...BcryptPasswordOption) (Plaintext, error)