hash

package
v1.18.4 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 12 Imported by: 4

Documentation

Index

Constants

View Source
const DefaultHashAlgorithmName = "pbkdf2"

Variables

View Source
var RecommendedHashAlgorithms = []string{
	"pbkdf2",
	"argon2",
	"bcrypt",
	"scrypt",
	"pbkdf2_hi",
}

Functions

func Register

func Register[T PasswordSaltHasher](name string, newFn func(config string) T)

Register registers a PasswordSaltHasher with the availableHasherFactories This is not thread safe.

Types

type Argon2Hasher

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

Argon2Hasher implements PasswordHasher and uses the Argon2 key derivation function, hybrant variant

func NewArgon2Hasher

func NewArgon2Hasher(config string) *Argon2Hasher

NewArgon2Hasher is a factory method to create an Argon2Hasher The provided config should be either empty or of the form: "<time>$<memory>$<threads>$<keyLen>", where <x> is the string representation of an integer

func (*Argon2Hasher) HashWithSaltBytes

func (hasher *Argon2Hasher) HashWithSaltBytes(password string, salt []byte) string

HashWithSaltBytes a provided password and salt

type BcryptHasher

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

BcryptHasher implements PasswordHasher and uses the bcrypt password hash function.

func NewBcryptHasher

func NewBcryptHasher(config string) *BcryptHasher

NewBcryptHasher is a factory method to create an BcryptHasher The provided config should be either empty or the string representation of the "<cost>" as an integer

func (*BcryptHasher) HashWithSaltBytes

func (hasher *BcryptHasher) HashWithSaltBytes(password string, salt []byte) string

HashWithSaltBytes a provided password and salt

func (*BcryptHasher) VerifyPassword

func (hasher *BcryptHasher) VerifyPassword(password, hashedPassword, salt string) bool

type PBKDF2Hasher

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

PBKDF2Hasher implements PasswordHasher and uses the PBKDF2 key derivation function.

func NewPBKDF2Hasher

func NewPBKDF2Hasher(config string) *PBKDF2Hasher

NewPBKDF2Hasher is a factory method to create an PBKDF2Hasher config should be either empty or of the form: "<iter>$<keyLen>", where <x> is the string representation of an integer

func (*PBKDF2Hasher) HashWithSaltBytes

func (hasher *PBKDF2Hasher) HashWithSaltBytes(password string, salt []byte) string

HashWithSaltBytes a provided password and salt

type PasswordHashAlgorithm

type PasswordHashAlgorithm struct {
	PasswordSaltHasher
	Name string
}

PasswordHashAlgorithms are named PasswordSaltHashers with a default verifier and hash function

var DefaultHashAlgorithm *PasswordHashAlgorithm

func Parse

func Parse(algorithm string) *PasswordHashAlgorithm

func SetDefaultPasswordHashAlgorithm

func SetDefaultPasswordHashAlgorithm(algorithmName string) (string, *PasswordHashAlgorithm)

func (*PasswordHashAlgorithm) Hash

func (algorithm *PasswordHashAlgorithm) Hash(password, salt string) (string, error)

Hash the provided password with the salt and return the hash

func (*PasswordHashAlgorithm) VerifyPassword

func (algorithm *PasswordHashAlgorithm) VerifyPassword(providedPassword, hashedPassword, salt string) bool

Verify the provided password matches the hashPassword when hashed with the salt

type PasswordHasher

type PasswordHasher interface {
	Hash(password, salt string) (string, error)
}

PasswordHasher will hash a provided password with the salt

type PasswordSaltHasher

type PasswordSaltHasher interface {
	HashWithSaltBytes(password string, saltBytes []byte) string
}

PasswordSaltHasher will hash a provided password with the provided saltBytes

type PasswordVerifier

type PasswordVerifier interface {
	VerifyPassword(providedPassword, hashedPassword, salt string) bool
}

PasswordVerifier will ensure that a providedPassword matches the hashPassword when hashed with the salt

type ScryptHasher

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

ScryptHasher implements PasswordHasher and uses the scrypt key derivation function.

func NewScryptHasher

func NewScryptHasher(config string) *ScryptHasher

NewScryptHasher is a factory method to create an ScryptHasher The provided config should be either empty or of the form: "<n>$<r>$<p>$<keyLen>", where <x> is the string representation of an integer

func (*ScryptHasher) HashWithSaltBytes

func (hasher *ScryptHasher) HashWithSaltBytes(password string, salt []byte) string

HashWithSaltBytes a provided password and salt

Jump to

Keyboard shortcuts

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