Documentation ¶
Overview ¶
Package password provides password hashing and validation.
Package password provides password hashing and validation.
Package password provides password hashing and validation.
Package password provides password hashing and validation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Md5 is the MD5 implementation of the Hasher interface. Md5 = NewMd5Hasher() // Bcrypt is the bcrypt implementation of the Hasher interface. Bcrypt = NewBcryptHasher(nil) // DefaultHasher is the default hasher used by the package. DefaultHasher = NewMd5Hasher() )
var ( // Md5Val is the MD5 implementation of the Validator interface. Md5Val = Md5Validator{DefaultMd5Config} // BcryptVal is the bcrypt implementation of the Validator interface. BcryptVal = BcryptValidator{} )
var DefaultBcryptConfig = &BcryptConfig{Cost: 10}
DefaultBcryptConfig is the default configuration for bcrypt hashing.
var DefaultMd5Config = &Md5Config{SaltLength: 8}
DefaultMd5Config is the default configuration for md5 hashing.
var ErrMismatchedHashAndPassword = errors.New("mismatched password hash and password")
ErrMismatchedHashAndPassword is returned when the password hash and password do not match.
var ErrUnknownHashAlgorithm = errors.New("unknown hash algorithm")
ErrUnknownHashAlgorithm is returned when the hash algorithm is unknown.
Functions ¶
func GenerateHash ¶
GenerateHash generates a hash of the given password using the provided hasher algorithm.
Types ¶
type BcryptConfig ¶
type BcryptConfig struct { // Cost is the bcrypt cost parameter. The cost parameter controls the // amount of computation required to hash the password. The higher the // cost, the more secure the password hash will be. The default cost is // 10. Cost int }
BcryptConfig is the configuration for bcrypt hashing.
type BcryptHasher ¶
type BcryptHasher struct {
*BcryptConfig
}
BcryptHasher is the bcrypt implementation of the Hasher interface.
func NewBcryptHasher ¶
func NewBcryptHasher(config *BcryptConfig) *BcryptHasher
NewBcryptHasher returns a new bcrypt hasher with the default configuration.
func (*BcryptHasher) GenerateHash ¶
func (h *BcryptHasher) GenerateHash(password string) (string, error)
GenerateHash generates a bcrypt hash of the given password.
type BcryptValidator ¶
type BcryptValidator struct{}
BcryptValidator is the bcrypt implementation of the Validator interface.
func (BcryptValidator) ValidateHash ¶
func (v BcryptValidator) ValidateHash(passwordHash string, password string) error
ValidateHash validates the given password hash against the given password.
type Md5Config ¶
type Md5Config struct {
SaltLength int
}
Md5Config contains the settings specific for md5 hashing.
type Md5Hasher ¶
type Md5Hasher struct {
*Md5Config
}
Md5Hasher is the md5 implementation of the Hasher interface.
func NewMd5Hasher ¶
func NewMd5Hasher() *Md5Hasher
NewMd5Hasher returns a new md5 hasher with the default configuration.
func (*Md5Hasher) GenerateHash ¶
GenerateHash generates a md5 hash of the given password.
type Md5Validator ¶
type Md5Validator struct {
*Md5Config
}
Md5Validator is the md5 implementation of the Validator interface.
func (Md5Validator) ValidateHash ¶
func (v Md5Validator) ValidateHash(passwordHash string, password string) error
ValidateHash validates the given password hash against the given password. It returns an error if the password is invalid.
type Validator ¶
Validator is the interface that wraps the ValidateHash method.
func DetermineValidatorAlgorithm ¶
DetermineValidatorAlgorithm determines the validator algorithm based on the given hash.
type ValidatorFunction ¶
ValidatorFunction is a function type that validates a password hash against a password.
func GetValidatorFunc ¶
func GetValidatorFunc(hash string) ValidatorFunction
GetValidatorFunc determines the validator function based on the given hash.