password

package
v0.0.0-...-dab71c7 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package password implements convenience types and functions for dealing with passwords. The default parameters are based on recommendations for interactive use and should be okay. In its simplest form you just use the default parameters to hash passwords:

hash, err := HashWithParam(DefaultInteractiveParameters, "mySecretPassword")

Then to verify the hash you can do

res, err := Verify(hash, "mySecretPassword")

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultInteractiveParameters are the recommended parameters for interactive use.
	// We might want to tweak those a bit.
	DefaultInteractiveParameters = Params{
		Time:    uint32(1),
		Memory:  uint32(64 * 1024),
		Threads: uint8(4),
		KeyLen:  uint32(32),
	}
)

Functions

func Hash

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

Hash a password with the default parameters. The returned byte slice is a serialized hash including the parameters.

You should prefer to use this unless you have given the parameters some thought since we will try to maintain the DefaultInteractiveParameters and ensure they have appropriate values.

func HashWithParam

func HashWithParam(p Params, password string) ([]byte, error)

HashWithParam hashes a password with a given parameter set. The returned byte slice is a serialized hash including the parameters.

Returns an error if rand.Read fails - which it shouldn't.

func Verify

func Verify(password string, hash []byte) (bool, error)

Verify that password matches (serialized) hash.

Types

type Params

type Params struct {
	Time    uint32
	Memory  uint32
	Threads uint8
	KeyLen  uint32
}

Params represents the parameters used for password hashing.

type ParsedParams

type ParsedParams struct {
	Version int
	Time    uint32
	Memory  uint32
	Threads uint8
	Salt    []byte
	Hash    []byte
}

ParsedParams represents the parameters extracted from the serialized hash.

func DecodeParamsFromHash

func DecodeParamsFromHash(hash []byte) (*ParsedParams, error)

DecodeParamsFromHash decodes the passwod hashing parameters from the serialized password hash.

Jump to

Keyboard shortcuts

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