auth

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidHash         = errors.New("invalid hash")
	ErrIncompatibleVersion = errors.New("incompatible version")
)

Functions

func GenerateNonce

func GenerateNonce(entropy uint) []byte

GenerateNonce returns an array of cryptographically randomly generated bytes with the given entropy.

func GenerateURLSafeNonce

func GenerateURLSafeNonce(entropy uint) string

GenerateURLSafeNonce returns a base64 url encoded nonce with the given bytes of entropy.

Types

type Argon2

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

func NewArgon2

func NewArgon2(opts ...Argon2Option) *Argon2

NewArgon2 returns a new instance of the Argon2 password provider.

Defaults:

  • memory: 64MB
  • time: 3
  • threads: 2
  • salt length: 16
  • key length: 32

func (*Argon2) ComparePasswordAndHash

func (a *Argon2) ComparePasswordAndHash(password, hash string) (bool, error)

ComparePasswordAndHash compares the given password and hash to see if they match. Errors are only returned if the hash is malformed, or the argon2 version specified in the hash is incorrect.

func (*Argon2) GenerateFromPassword

func (a *Argon2) GenerateFromPassword(password string) string

GenerateFromPassword hashes the given password and returns the hash.

type Argon2Option

type Argon2Option func(*Argon2)

Argon2Option provides a functional way to configure the argon2 password provider

func WithKeyLength

func WithKeyLength(length uint32) Argon2Option

WithKeyLength sets the length of the raw key to be generated. The value 0 is ignored.

func WithMemory

func WithMemory(memory uint32) Argon2Option

WithMemory sets the memory cost. The value 0 is ignored.

func WithSaltLength

func WithSaltLength(length uint32) Argon2Option

WithSaltLength sets the length of the raw salt to be generated. The value 0 is ignored.

func WithThreads

func WithThreads(threads uint8) Argon2Option

WithThreads sets the number of threads to be used. The value 0 is ignored.

func WithTime

func WithTime(time uint32) Argon2Option

WithTime sets the time cost. The value 0 is ignored.

Jump to

Keyboard shortcuts

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