Documentation ¶
Overview ¶
Package password provides function to work with password and password hashes.
It contains crypto logic in one place and provide convenient interface for other parts of the app. Main functions are `HashAndEncode` for generating hash from a plaintext password and `Check` that compares plaintext password against encoded string created with `HashAndEncode`.
This packages uses Argon2 for password hashing with unique per-password salt and hash params that are described in package constants.
Index ¶
Constants ¶
const ( // Default parameters for hashing DefaultIterations = 5 DefaultMemory = 32 * 1024 // 32MiB DefaultThreads = 1 DefaultLen = 64 ErrHashInvalid = passwordError("invalid hash format") ErrHashType = passwordError("invalid hash type") ErrHashVersion = passwordError("invalid hash version") ErrHashParams = passwordError("invalid hash params") ErrHashSalt = passwordError("invalid hash salt") ErrHash = passwordError("invalid hash") )
Variables ¶
This section is empty.
Functions ¶
func Encode ¶
func Encode(hash []byte, params HashParams) string
Encode converts hash from byte slice to the string with hash params including salt
func HashAndEncode ¶
HashAndEncode creates Argon2 password hash for a given plaintext password using default hash parameters and returns its encoded representation
func HashWithParams ¶
func HashWithParams(password string, params HashParams) []byte
genHash generates password hash for a given plaintext password using given params
Types ¶
type HashParams ¶
HashParams describe parameters for Argon2 hashing. These parameters are encoded in the Encode function.
func Decode ¶
func Decode(s string) ([]byte, HashParams, error)
Decode converts hash from encoded string to the byte slice of hashed password and the struct of hash params
func Hash ¶
func Hash(password string) ([]byte, HashParams, error)
Hash creates Argon2 password hash for a given plaintext password using default hash parameters
func NewHashParams ¶
func NewHashParams() (HashParams, error)
NewHashParams creates hash params struct with default values