argon2/README.md

55 lines
1.3 KiB
Markdown
Raw Normal View History

2022-12-04 02:18:05 +01:00
# Argon2 utils
## About
Utils to encrypt passwords using argon2
2023-09-13 11:44:56 +02:00
## Usages
2022-12-04 02:18:05 +01:00
2023-09-13 11:44:56 +02:00
### Hash password
2022-12-04 02:18:05 +01:00
````go
2023-09-13 11:44:56 +02:00
password := 'qwerty@123'
// Create new encoder using default options
encoder, _ := argon2.NewEncoder()
hashedString, err = encoder.HashString(randomString)
if err != nil {
// handle error
2022-12-04 02:18:05 +01:00
}
````
2023-09-13 11:44:56 +02:00
### 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
)
````
2022-12-04 02:18:05 +01:00
## Contributions
2022-12-04 02:36:16 +01:00
**Euphoria Laxis** [GitHub](https://github.com/euphoria-laxis)
2022-12-04 02:18:05 +01:00
## License
This project is under [MIT License](./LICENSE)