hash

package
v0.0.0-...-947ddfb Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidHash         = stackerrors.New("the encoded hash is not in the correct format")
	ErrWrongHashAlgorithm  = stackerrors.New("the hashing algorithm is not correct")
	ErrIncompatibleVersion = stackerrors.New("incompatible version of argon2")
)

Functions

This section is empty.

Types

type Argon2ID

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

Argon2ID implements the Hasher interface. Underneath, it uses the Argon2ID implementation to hash passwords and compare passwords.

func NewArgon2ID

func NewArgon2ID(memory, iterations uint32, parallelism uint8, saltLength, keyLength uint32) *Argon2ID

func (*Argon2ID) ComparePasswordAndHash

func (a *Argon2ID) ComparePasswordAndHash(password, encodedHash string) (match bool, err error)

ComparePasswordAndHash takes a password and the hash, and extracts the salt and strength parameters, and compares the hashes in constant time (avoiding time collision attacks).

func (*Argon2ID) HashPassword

func (a *Argon2ID) HashPassword(password string) (encodedHash string, err error)

HashPassword takes in a password string and hashes + salts it using the Argon2ID algorithm. It is recommended that you pass in a password + pepper combination, because the pepper should be a secret value that is not stored alongside the hashed password.

The password is stored in the following format:

$argon2id$v={version}$m={memory},t={iterations},p={parallelism}${salt}${hash}

Jump to

Keyboard shortcuts

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