From 65f77f11b5b093cde46cf363803025b4ae7b3b73 Mon Sep 17 00:00:00 2001 From: euphoria-laxis Date: Sun, 13 Oct 2024 01:30:43 +0200 Subject: [PATCH] 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