simple-argon2 provides a convenience wrapper around Go's existing argon2 (formaly argon2id
) package that makes it easier to securely derive strong keys ("hash user passwords").
Based on article How to Hash and Verify Passwords With Argon2 in Go and strongly inspired of github.com/elithrar/simple-scrypt package (source code, comments & readme).
The API closely mirrors Go's bcrypt library in an effort to make it easy to migrate—and because it's an easy to grok API.
go get github.com/mdouchement/simple-argon2
package main
import (
"fmt"
"log"
argon2 "github.com/mdouchement/simple-argon2"
)
func main() {
hashed, err := argon2.GenerateFromPasswordString("42password42", argon2.Default)
if err != nil {
log.Fatal(err)
}
fmt.Println(hashed)
// $argon2id$v=19$m=65536,t=3,p=2$/lASHr1GVXVkV/628wFUVGqINrLbWo7v86TjaooJmUY$igyAvrODju4SsBSefcYOzMaLl9xGjSkjsY1tnaKaTxk
err = argon2.CompareHashAndPasswordString(hashed, "42password42")
if err != nil {
// Invalid password
log.Fatal(err)
}
// Valid password
}
MIT
All PRs are welcome.
- Fork it
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
As possible, run the following commands to format and lint the code:
# Format
find . -name '*.go' -exec gofmt -s -w {} \;
# Lint
golangci-lint run -c .golangci.yml