staging/v0.1.2 new version 0.1.2 #2
74
.gitea/workflows/testing.yml
Normal file
74
.gitea/workflows/testing.yml
Normal file
|
@ -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 ./...
|
63
README.md
63
README.md
|
@ -4,28 +4,70 @@
|
||||||
|
|
||||||
Utils to encrypt passwords using argon2
|
Utils to encrypt passwords using argon2
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
Download package in your project module:
|
||||||
|
|
||||||
|
````bash
|
||||||
|
go get -u euphoria-laxis.fr/go-packages/argon2
|
||||||
|
````
|
||||||
|
|
||||||
## Usages
|
## Usages
|
||||||
|
|
||||||
### Hash password
|
### Hash password
|
||||||
|
|
||||||
````go
|
````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
|
// Create new encoder using default options
|
||||||
encoder, _ := argon2.NewEncoder()
|
encode, _ := encoder.NewEncoder()
|
||||||
hashedString, err = encoder.HashString(randomString)
|
hashedString, err := encode.HashString(password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// handle error
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Println(hashedString)
|
||||||
}
|
}
|
||||||
````
|
````
|
||||||
|
|
||||||
### Compare password with hashed string
|
### Compare password with hashed string
|
||||||
|
|
||||||
````go
|
````go
|
||||||
// Create new decoder using default options
|
package main
|
||||||
decoder, _ := argon2.NewDecoder()
|
|
||||||
match, err := decoder.CompareStringToHash(password, hashedString)
|
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 {
|
if err != nil {
|
||||||
// handle error
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
````
|
````
|
||||||
|
|
||||||
|
@ -36,18 +78,19 @@ You can use the same `argon2.OptFunc` slice to configure both encoder and decode
|
||||||
|
|
||||||
````go
|
````go
|
||||||
// Create new encoder using custom parameters
|
// Create new encoder using custom parameters
|
||||||
encoder, options := argon2.NewEncoder(
|
enc, options := encoder.NewEncoder(
|
||||||
SetMemory(64 * 1024), // 64 bits
|
SetMemory(64 * 1024), // 64 bits
|
||||||
SetParallelism(4), // 4 concurrent actions
|
SetParallelism(4), // 4 concurrent actions
|
||||||
SetKeyLength(32), // key length
|
SetKeyLength(32), // key length
|
||||||
SetSaltLength(32), // salt length
|
SetSaltLength(32), // salt length
|
||||||
SetIterations(4), // number of iterations
|
SetIterations(4), // number of iterations
|
||||||
)
|
)
|
||||||
|
// Decoder use the same functions
|
||||||
````
|
````
|
||||||
|
|
||||||
## Contributions
|
## Contributions
|
||||||
|
|
||||||
**Euphoria Laxis** [GitHub](https://github.com/euphoria-laxis)
|
**Euphoria Laxis** [Gitea](https://euphoria-laxis.fr/euphoria-laxis)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
6
go.mod
6
go.mod
|
@ -1,7 +1,7 @@
|
||||||
module euphoria-laxis.fr/go-packages/argon2
|
module euphoria-laxis.fr/go-packages/argon2
|
||||||
|
|
||||||
go 1.22
|
go 1.23
|
||||||
|
|
||||||
require golang.org/x/crypto v0.25.0
|
require golang.org/x/crypto v0.28.0
|
||||||
|
|
||||||
require golang.org/x/sys v0.22.0 // indirect
|
require golang.org/x/sys v0.26.0 // indirect
|
||||||
|
|
8
go.sum
8
go.sum
|
@ -1,4 +1,4 @@
|
||||||
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
|
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
|
||||||
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
|
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
|
||||||
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||||
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
|
Loading…
Reference in New Issue
Block a user