argon2
Easy to use Argon2 password hashing for Go.
Provides an interface around golang.org/x/crypto/argon2 similar to the interface of the golang.org/x/crypto/bcrypt package.
Examples
Create Password Hash
package main
import (
"fmt"
"log"
"github.com/judwhite/argon2"
)
func main() {
// user input
password := []byte("some password")
str, err := argon2.GenerateFromPassword(password, argon2.Options{})
if err != nil {
log.Fatal(err)
}
fmt.Println(str) // store this output in a database
}
Validate Password Hash
package main
import (
"fmt"
"log"
"github.com/judwhite/argon2"
)
func main() {
// retrieved from a database
const hash = "$argon2id$v=19$m=98304,t=5,p=2$AAECAwQFBgcICQoLDA0ODw$Ezmo1ZvImYjNdSrjbN33VEd5aUBeSmP3YZAojYw467I"
// user input
password := []byte("some password")
// validate passwords match
if err := argon2.CompareHashAndPassword(hash, password); err != nil {
log.Fatal(err)
}
fmt.Println("passwords match")
}
Similar Projects
- https://godoc.org/golang.org/x/crypto/argon2
- https://github.com/p-h-c/phc-winner-argon2
- https://github.com/alexedwards/argon2id
License
argon2 is under the MIT license. See the LICENSE file for details.