Skip to content

A convenience library for generating, comparing and inspecting password hashes using the argon2 KDF in Go.

License

Notifications You must be signed in to change notification settings

mdouchement/simple-argon2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A convenience library for generating, comparing and inspecting password hashes using the argon2 KDF in Go.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages