Go package to simplify common use cases with argon2i
Go to file
2024-11-28 22:48:55 +01:00
.gitea/workflows Add test action, run package go tests 2024-10-13 01:31:33 +02:00
.gitignore Initial commit 2024-07-24 23:44:50 +02:00
decoder_test.go Set version and remove subpackages 2024-11-28 22:04:03 +01:00
decoder.go Set version and remove subpackages 2024-11-28 22:04:03 +01:00
encoder_test.go Set version and remove subpackages 2024-11-28 22:04:03 +01:00
encoder.go Set version and remove subpackages 2024-11-28 22:04:03 +01:00
go.mod Set version and remove subpackages 2024-11-28 22:04:03 +01:00
go.sum Update package name, go version and dependencies 2024-10-13 01:30:23 +02:00
LICENSE Add README.md and LICENSE 2024-07-24 23:48:36 +02:00
options.go Set version and remove subpackages 2024-11-28 22:04:03 +01:00
README.md Update README.md 2024-10-13 01:30:44 +02:00

Argon2 utils

About

Utils to encrypt passwords using argon2

Install

Download package in your project module:

go get -u euphoria-laxis.fr/go-packages/argon2

Usages

Hash password

package main

import (
	"fmt"

    "euphoria-laxis.fr/go-packages/argon2/encoder"
)

func main() {
    password := "qwerty@123"
    // Create new encoder using default options
    encode, _ := encoder.NewEncoder()
    hashedString, err := encode.HashString(password)
    if err != nil {
		panic(err)
    }
	fmt.Println(hashedString)
}

Compare password with hashed string

package main

import (
	"fmt"
	
	"euphoria-laxis.fr/go-packages/argon2/encoder"
	"euphoria-laxis.fr/go-packages/argon2/decoder"
)

func main() {
	password := "qwerty@123"
	// Create new encoder using default options
	enc, _ := encoder.NewEncoder()
	hashedString, err := enc.HashString(password)
	if err != nil {
		panic(err)
	}
	fmt.Println(hashedString)
	// Create new decoder using default options
	dec := decoder.NewDecoder()
	var match bool
	match, err = dec.CompareStringToHash(password, hashedString)
	if err != nil {
		panic(err)
	}
	if !match {
		fmt.Println("wrong password")
    }
}

Configure encoder or decoder options

Note that encoder and decoder inherited from the same base struct (argon2.Options). You can use the same argon2.OptFunc slice to configure both encoder and decoder.

    // Create new encoder using custom parameters
    enc, options := encoder.NewEncoder(
        SetMemory(64 * 1024), // 64 bits
        SetParallelism(4),    // 4 concurrent actions
        SetKeyLength(32),     // key length
        SetSaltLength(32),    // salt length
        SetIterations(4),     // number of iterations
    )
	// Decoder use the same functions

Contributions

Euphoria Laxis Gitea

License

This project is under MIT License