Update README.md Usages section
Some checks failed
Test github.com/euphoria-laxis/argon2 / build (push) Has been cancelled
Some checks failed
Test github.com/euphoria-laxis/argon2 / build (push) Has been cancelled
This commit is contained in:
parent
b8cd7c483d
commit
2abf56dfd6
52
README.md
52
README.md
|
@ -4,30 +4,46 @@
|
||||||
|
|
||||||
Utils to encrypt passwords using argon2
|
Utils to encrypt passwords using argon2
|
||||||
|
|
||||||
## Usage
|
## Usages
|
||||||
|
|
||||||
### Example
|
### Hash password
|
||||||
|
|
||||||
````go
|
````go
|
||||||
func func main() {
|
password := 'qwerty@123'
|
||||||
password := 'qwerty@123'
|
// Create new encoder using default options
|
||||||
hashedString, err := argon2_utils.HashStringArgon2(password)
|
encoder, _ := argon2.NewEncoder()
|
||||||
if err != nil {
|
hashedString, err = encoder.HashString(randomString)
|
||||||
...
|
if err != nil {
|
||||||
}
|
// handle error
|
||||||
match, err := argon2_utils.CompareStringToArgon2Hash(password, hashedString)
|
|
||||||
if err != nil {
|
|
||||||
...
|
|
||||||
}
|
|
||||||
if !match {
|
|
||||||
log.Println("passwords don't match")
|
|
||||||
} else {
|
|
||||||
log.Println("passwords match")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
````
|
````
|
||||||
|
|
||||||
This package also contains a **RandomString(int)(string,error)** function.
|
### 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
|
||||||
|
}
|
||||||
|
````
|
||||||
|
|
||||||
|
### 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.
|
||||||
|
|
||||||
|
````go
|
||||||
|
// Create new encoder using custom parameters
|
||||||
|
encoder, options := argon2.NewEncoder(
|
||||||
|
SetMemory(64 * 1024), // 64 bits
|
||||||
|
SetParallelism(4), // 4 concurrent actions
|
||||||
|
SetKeyLength(32), // key length
|
||||||
|
SetSaltLength(32), // salt length
|
||||||
|
SetIterations(4), // number of iterations
|
||||||
|
)
|
||||||
|
````
|
||||||
|
|
||||||
## Contributions
|
## Contributions
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user