staging/v0.1.2 new version 0.1.2 #2

Merged
euphoria-laxis merged 10 commits from staging/v0.1.2 into master 2024-10-13 03:18:24 +02:00
Showing only changes of commit 65f77f11b5 - Show all commits

View File

@ -4,29 +4,71 @@
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 (
if err != nil { "fmt"
// handle error
"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 ### Configure encoder or decoder options
@ -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