From ba8fdf44edf776e349230f88d135093923ccce3a Mon Sep 17 00:00:00 2001 From: euphoria-laxis Date: Sun, 11 Aug 2024 23:21:50 +0200 Subject: [PATCH 1/5] Update dependencies --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index b43777c..909080e 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,6 @@ module euphoria-laxis.fr/go-packages/argon2 go 1.22 -require golang.org/x/crypto v0.25.0 +require golang.org/x/crypto v0.26.0 -require golang.org/x/sys v0.22.0 // indirect +require golang.org/x/sys v0.24.0 // indirect diff --git a/go.sum b/go.sum index c339b1b..a07bc7d 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ -golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= -golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -- 2.43.0 From fa3837205e3ad2e54115b12ed267e47d577313ef Mon Sep 17 00:00:00 2001 From: euphoria-laxis Date: Mon, 12 Aug 2024 00:22:43 +0200 Subject: [PATCH 2/5] Set repository in go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 909080e..8a25934 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module euphoria-laxis.fr/go-packages/argon2 +module github.com/euphoria-laxis/argon2 go 1.22 -- 2.43.0 From 0588199222edb4503aded01157e3fbcd032a31e7 Mon Sep 17 00:00:00 2001 From: euphoria-laxis Date: Sun, 13 Oct 2024 01:30:17 +0200 Subject: [PATCH 3/5] Update package name, go version and dependencies --- go.mod | 8 ++++---- go.sum | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 8a25934..2b4f819 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ -module github.com/euphoria-laxis/argon2 +module euphoria-laxis.fr/go-packages/argon2 -go 1.22 +go 1.23 -require golang.org/x/crypto v0.26.0 +require golang.org/x/crypto v0.28.0 -require golang.org/x/sys v0.24.0 // indirect +require golang.org/x/sys v0.26.0 // indirect diff --git a/go.sum b/go.sum index a07bc7d..25fba75 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ -golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= -golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= -golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= -golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= +golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -- 2.43.0 From 65f77f11b5b093cde46cf363803025b4ae7b3b73 Mon Sep 17 00:00:00 2001 From: euphoria-laxis Date: Sun, 13 Oct 2024 01:30:43 +0200 Subject: [PATCH 4/5] Update README.md --- README.md | 65 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 40676a2..ec983ec 100644 --- a/README.md +++ b/README.md @@ -4,29 +4,71 @@ Utils to encrypt passwords using argon2 +## Install + +Download package in your project module: + +````bash +go get -u euphoria-laxis.fr/go-packages/argon2 +```` + ## Usages ### Hash password ````go - password := 'qwerty@123' +package main + +import ( + "fmt" + + "euphoria-laxis.fr/go-packages/argon2/encoder" +) + +func main() { + password := "qwerty@123" // Create new encoder using default options - encoder, _ := argon2.NewEncoder() - hashedString, err = encoder.HashString(randomString) + encode, _ := encoder.NewEncoder() + hashedString, err := encode.HashString(password) if err != nil { - // handle error + panic(err) } + fmt.Println(hashedString) +} ```` ### Compare password with hashed string ````go - // Create new decoder using default options - decoder, _ := argon2.NewDecoder() - match, err := decoder.CompareStringToHash(password, hashedString) - if err != nil { - // handle error +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 @@ -36,18 +78,19 @@ You can use the same `argon2.OptFunc` slice to configure both encoder and decode ````go // Create new encoder using custom parameters - encoder, options := argon2.NewEncoder( + 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** [GitHub](https://github.com/euphoria-laxis) +**Euphoria Laxis** [Gitea](https://euphoria-laxis.fr/euphoria-laxis) ## License -- 2.43.0 From f7c114f35bb1143c4ca05d782939c200684898b5 Mon Sep 17 00:00:00 2001 From: euphoria-laxis Date: Sun, 13 Oct 2024 01:31:29 +0200 Subject: [PATCH 5/5] Add test action, run package go tests --- .gitea/workflows/testing.yml | 74 ++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 .gitea/workflows/testing.yml diff --git a/.gitea/workflows/testing.yml b/.gitea/workflows/testing.yml new file mode 100644 index 0000000..9e919da --- /dev/null +++ b/.gitea/workflows/testing.yml @@ -0,0 +1,74 @@ +name: test argon2 package +on: + push: + branches: + - staging/* + pull_request: + branches: + - master + - release/* + - staging/* + +env: + GOPATH: /go_path + GOCACHE: /go_cache + +jobs: + lint: + name: check and test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # all history for all branches and tags + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + check-latest: true + - uses: https://gitea.com/actions/go-hashfiles@v0.0.1 + id: hash-go + with: + patterns: | + go.mod + go.sum + - name: cache go + id: cache-go + uses: actions/cache@v4 + with: + path: | + /go_path + /go_cache + key: go_path-${{ steps.hash-go.outputs.hash }} + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + args: --timeout 5m + testing: + name: check and test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 # all history for all branches and tags + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + check-latest: true + - uses: https://gitea.com/actions/go-hashfiles@v0.0.1 + id: hash-go + with: + patterns: | + go.mod + go.sum + - name: cache go + id: cache-go + uses: actions/cache@v4 + with: + path: | + /go_path + /go_cache + key: go_path-${{ steps.hash-go.outputs.hash }} + - name: test + run: go test -v ./... \ No newline at end of file -- 2.43.0