Categorygithub.com/KEINOS/go-argonize
modulepackage
1.4.0
Repository: https://github.com/keinos/go-argonize.git
Documentation: pkg.go.dev

# README

go-argonize

go1.22+ Go Reference

Go package to facilitate the use of the Argon2id password hashing algorithm from the "crypto/argon2" package.

go get "github.com/KEINOS/go-argonize"
func Example() {
    // Your strong and unpredictable password
    password := []byte("my password")

    // Password hash your password
    hashedObj, err := argonize.Hash(password)
    if err != nil {
        log.Fatal(err)
    }

    // View the hashed password
    fmt.Println("Passwd to save:", hashedObj.String())

    // Verify password (golden case)
    if hashedObj.IsValidPassword([]byte("my password")) {
        fmt.Println("the password is valid")
    } else {
        fmt.Println("the password is invalid")
    }

    // Verify password (wrong case)
    if hashedObj.IsValidPassword([]byte("wrong password")) {
        fmt.Println("the password is valid")
    } else {
        fmt.Println("the password is invalid")
    }

    // Output:
    // Passwd to save: $argon2id$v=19$m=65536,t=1,p=2$ek6ZYdlRm2D5AsGV98TWKA$QAIDZEdIgwohrNX678mHc448LOmD7jGR4BGw/9YMMVU
    // the password is valid
    // the password is invalid
}

Contributing

go1.22+ Go Reference Opened Issues PR

Any Pull-Request for improvement is welcome!

Statuses

UnitTests golangci-lint CodeQL-Analysis PlatformTests

codecov Go Report Card

License, copyright and credits

# Functions

DecodeHashGob decodes gob-encoded byte slice into a Hashed object.
DecodeHashStr decodes an Argon2id formatted hash string into a Hashed object.
Hash returns a Hashed object from the password using the Argon2id algorithm.
HashCustom returns a Hashed object from the password using the Argon2id algorithm.
NewParams returns a new Params object with default values.
NewSalt returns a new Salt object with a random salt and given length.
RandomBytes returns a random number of byte slice with the given length.

# Constants

IterationsDefault is the default number of iterations of the parameter used by the Argon2id algorithm.
KeyLengthDefault is the default key length used in the Argon2id algorithm parameters.
MemoryCostDefault is the default amount of memory (KiB) used by the algorithm parameters.
ParallelismDefault is the default number of threads used in the algorithm parameters.
SaltLengthDefault is the default length of the salt used in the Argon2id algorithm parameters.

# Variables

RandRead is a copy of `crypto.rand.Read` to ease testing.

# Structs

Hashed holds the Argon2id hash value and its parameters.
Params holds the parameters for the Argon2id algorithm.

# Type aliases

Salt holds the salt value.