Version: v0.0.0-...-57de6aa Latest Latest

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

Go to latest
Published: Oct 25, 2019 License: BSD-3-Clause Imports: 10 Imported by: 0



Package pbkdf2 implements a Django compatible PBKDF2 algorithm.



This section is empty.


View Source
var (
	ErrHashComponentUnreadable = errors.New("unchained/pbkdf2: unreadable component in hashed password")
	ErrHashComponentMismatch   = errors.New("unchained/pbkdf2: hashed password components mismatch")
	ErrAlgorithmMismatch       = errors.New("unchained/pbkdf2: algorithm mismatch")
	ErrSaltContainsDollarSing  = errors.New("unchained/pbkdf2: salt contains dollar sign ($)")

Errors returned by PBKDF2Hasher.


This section is empty.


type PBKDF2Hasher

type PBKDF2Hasher struct {
	// Algorithm identifier.
	Algorithm string
	// Defines the number of rounds used to encode the password.
	Iterations int
	// Defines the length of the hash in bytes.
	Size int
	// Defines the hash function used to encode the password.
	Digest func() hash.Hash

PBKDF2Hasher implements PBKDF2 password hasher.

func NewPBKDF2SHA1Hasher

func NewPBKDF2SHA1Hasher() *PBKDF2Hasher

NewPBKDF2SHA1Hasher secures password hashing using the PBKDF2 algorithm.

Alternate PBKDF2 hasher which uses SHA1, the default PRF recommended by PKCS #5.

This is compatible with other implementations of PBKDF2, such as openssl's PKCS5_PBKDF2_HMAC_SHA1().

func NewPBKDF2SHA256Hasher

func NewPBKDF2SHA256Hasher() *PBKDF2Hasher

NewPBKDF2SHA256Hasher secures password hashing using the PBKDF2 algorithm.

Configured to use PBKDF2 + HMAC + SHA256. The result is a 64 byte binary string.

func (*PBKDF2Hasher) Encode

func (h *PBKDF2Hasher) Encode(password string, salt string, iterations int) (string, error)

Encode turns a plain-text password into a hash.

func (*PBKDF2Hasher) Verify

func (h *PBKDF2Hasher) Verify(password string, encoded string) (bool, error)

Verify if a plain-text password matches the encoded digest.

Source Files

Jump to

Keyboard shortcuts

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