judwhite / argon2

Easy to use Argon2 password hashing for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

argon2

GoDoc MIT License Go Report Card CircleCI

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

License

argon2 is under the MIT license. See the LICENSE file for details.

About

Easy to use Argon2 password hashing for Go

License:MIT License


Languages

Language:Go 100.0%