Awesome Open Source
Awesome Open Source

simple-argon2

GoDoc Go Report Card License

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.

Usage

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
}

License

MIT

Contributing

All PRs are welcome.

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. 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

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Go (196,482
Golang (32,788
Password (1,645
Hash (1,151
Related Projects