lib

package
v1.2.27 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidHash         = errors.New("the encoded hash is in an invalid format")
	ErrIncompatibleVersion = errors.New("the encoded hash is using an incompatible version of Argon2")
	ErrInvalidPassword     = errors.New("the password is invalid")

	ErrGenerateScrypt = errors.New("GenerateScrypt")
	ErrCompareScrypt  = errors.New("CompareScrypt")
	ErrDecodeHash     = errors.New("decodeHash")
)
View Source
var ErrNewRandomURLString = errors.New("NewRandomURLString")
View Source
var ScryptParamsDefault = ScryptParams{
	SaltLength:  32,
	Iterations:  1,
	Memory:      64 * 1024,
	Parallelism: 4,
	KeyLength:   32,
}
View Source
var URLCharList = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

URLCharList is a list of URL-valid characters, for generating random strings.

Functions

func CompareScrypt

func CompareScrypt(password, encodedHash string) error

CompareScrypt compares a password with an encoded hash generated by GenerateScrypt. It returns true if the password matches the hash, and false otherwise.

This method is similar to bcrypt.CompareHashAndPassword, but based on the newer Argon2 algorithm.

func GenerateScrypt

func GenerateScrypt(password string, params ScryptParams) (string, error)

GenerateScrypt is a secure hash method, similar to bcrypt.GenerateFromPassword, but based on the newer Argon2 algorithm.

func NewErrCompareScrypt

func NewErrCompareScrypt(err error) error

func NewErrDecodeHash

func NewErrDecodeHash(err error) error

func NewErrGenerateScrypt

func NewErrGenerateScrypt(err error) error

func NewErrNewRandomURLString

func NewErrNewRandomURLString(err error) error

func NewRandomURLString

func NewRandomURLString(length int) (string, error)

Types

type ScryptParams

type ScryptParams struct {
	// SaltLength is the length of the salt in bytes.
	SaltLength uint
	// Iterations is the number of iterations to use.
	Iterations uint32
	// Memory is the amount of memory used by the algorithm.
	Memory uint32
	// Parallelism is the number of threads to use.
	Parallelism uint8
	// KeyLength is the length of the derived key.
	KeyLength uint32
}

ScryptParams contains the parameters used to generate a hash using the Argon2 algorithm.

You can use ScryptParamsDefault unless you have specific requirements.

Jump to

Keyboard shortcuts

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