password

package
v0.0.0-...-8ba40cc Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package password provides function to work with password and password hashes.

It contains crypto logic in one place and provide convenient interface for other parts of the app. Main functions are `HashAndEncode` for generating hash from a plaintext password and `Check` that compares plaintext password against encoded string created with `HashAndEncode`.

This packages uses Argon2 for password hashing with unique per-password salt and hash params that are described in package constants.

Index

Constants

View Source
const (

	// Default parameters for hashing
	DefaultIterations = 5
	DefaultMemory     = 32 * 1024 // 32MiB
	DefaultThreads    = 1
	DefaultLen        = 64

	ErrHashInvalid = passwordError("invalid hash format")
	ErrHashType    = passwordError("invalid hash type")
	ErrHashVersion = passwordError("invalid hash version")
	ErrHashParams  = passwordError("invalid hash params")
	ErrHashSalt    = passwordError("invalid hash salt")
	ErrHash        = passwordError("invalid hash")
)

Variables

This section is empty.

Functions

func Check

func Check(password string, encoded string) (bool, error)

Check takes plaintext password and compares it to the encoded hash value

func Encode

func Encode(hash []byte, params HashParams) string

Encode converts hash from byte slice to the string with hash params including salt

func HashAndEncode

func HashAndEncode(password string) (string, error)

HashAndEncode creates Argon2 password hash for a given plaintext password using default hash parameters and returns its encoded representation

func HashWithParams

func HashWithParams(password string, params HashParams) []byte

genHash generates password hash for a given plaintext password using given params

Types

type HashParams

type HashParams struct {
	Salt       []byte
	Iterations uint32
	Memory     uint32
	Threads    uint8
	Len        uint32
}

HashParams describe parameters for Argon2 hashing. These parameters are encoded in the Encode function.

func Decode

func Decode(s string) ([]byte, HashParams, error)

Decode converts hash from encoded string to the byte slice of hashed password and the struct of hash params

func Hash

func Hash(password string) ([]byte, HashParams, error)

Hash creates Argon2 password hash for a given plaintext password using default hash parameters

func NewHashParams

func NewHashParams() (HashParams, error)

NewHashParams creates hash params struct with default values

Jump to

Keyboard shortcuts

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