hasher

package module
v1.0.1-0...-0c4408b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2019 License: MIT Imports: 7 Imported by: 0

README

Argon2 hasher client

What is Argon2?

Argon2 is a key derivation function that was selected as the winner of the Password Hashing Competition in July 2015. It was designed by Alex Biryukov, Daniel Dinu, and Dmitry Khovratovich from the University of Luxembourg...

How to install:

go get github.com/kerak19/hasher

How to use:

package main

import "fmt"
import "github.com/kerak19/hasher"

func main() {
	hasher := hasher.Hasher{
		Params: hasher.Params{
			Memory:      64 * 1024,
			Iterations:  3,
			Parallelism: 2,
			SaltLength:  16,
			KeyLength:   32,
		},
	}

	password := "testpass"
	hashed, err := hasher.Hash(password)
	if err != nil {
		panic(err)
	}

	fmt.Println(hashed) // argon2&v=19&m=65536,t=3,p=2&08wK3zQr0Ol2UeuofUBcFQ&4LAUwzG2NUROQTIBOdqaNbAYnseewi6Q+5/y6UUwD3Q

	fmt.Println(hasher.ComparePasswordAndHash("testpass", hashed)) // true, <nil>
}

Package is loosely based on https://www.alexedwards.net/blog/how-to-hash-and-verify-passwords-with-argon2-in-go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidArgonVersion = errors.New("argon2 version is incompatible with hash version")
View Source
var ErrInvalidHash = errors.New("password hash is invalid")

Functions

This section is empty.

Types

type Hasher

type Hasher struct {
	Params Params
}

func New

func New() Hasher

New returns new Hasher with default parameters

func NewWithParams

func NewWithParams(p Params) Hasher

NewWithParams returns new hasher with custom parameters

func (Hasher) ComparePasswordAndHash

func (h Hasher) ComparePasswordAndHash(password, encHash string) (bool, error)

ComparePasswordAndHash compares provided password with hashed password. It'll return whether they match or not.

func (Hasher) Hash

func (h Hasher) Hash(password string) (string, error)

Hash generates hash for provided password with additional informations. These informations contains version of argon2, memory, iterations, parallelism and salt. The final format is the following: "hasher&v=version&m=memory,t=iterations,p=parallelism&salt&passwordHash".

func (Hasher) MustComparePasswordAndHash

func (h Hasher) MustComparePasswordAndHash(password, encHash string) bool

MustComparePasswordAndHash is same as ComparePasswordAndHash(), but panics if there's an error

func (Hasher) MustHash

func (h Hasher) MustHash(password string) string

MustHash is same as Hash(), but panics if there's an error

type Params

type Params struct {
	Memory      uint32
	Iterations  uint32
	Parallelism uint8
	SaltLength  uint32
	KeyLength   uint32
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL