pass

package
v0.0.1-0...-104a2d1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidHash         = errors.New("the encoded hash is not in the correct format")
	ErrIncompatibleVersion = errors.New("incompatible version of argon2")
	ErrInvalidPassword     = errors.New("password cannot be empty")

	// Minimum and maximum parameter bounds
	MinMemory      uint32 = 8 * 1024    // 8MB minimum
	MaxMemory      uint32 = 1024 * 1024 // 1GB maximum
	MinIterations  uint32 = 1
	MaxIterations  uint32 = 100
	MinParallelism uint8  = 1
	MaxParallelism uint8  = 255
)
View Source
var DefaultParams = &Params{
	Memory:      64 * 1024,
	Iterations:  3,
	Parallelism: 2,
	SaltLength:  16,
	KeyLength:   32,
}

DefaultParams sets the default parameters for Argon2 hashing.

Functions

func ComparePassAndHash

func ComparePassAndHash(password, encodedHash string) (bool, error)

ComparePassAndHash compares a password to an encoded hash to verify if they match. It returns true if the password matches the hash, otherwise false.

func GenerateRandomString

func GenerateRandomString(length int) (string, error)

GenerateRandomString generates a secure random string of the specified length

func HashPassword

func HashPassword(password string, params *Params) (string, error)

HashPassword hashes a password using Argon2 and the specified parameters. It returns the encoded hash or an error if hashing fails.

func ValidateParams

func ValidateParams(p *Params) error

ValidateParams validates the Argon2 parameters are within acceptable bounds.

Types

type Params

type Params struct {
	Memory      uint32
	Iterations  uint32
	Parallelism uint8
	SaltLength  uint32
	KeyLength   uint32
}

Params defines the parameters used for Argon2 hashing.

Jump to

Keyboard shortcuts

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