scheme

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

The scheme package contains an abstract description of the Scheme interface and additional error definitions.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPassword   = errors.New("invalid password")
	ErrUnsupportedScheme = errors.New("unsupported scheme")
)

Functions

func SecureCompare

func SecureCompare(a, b string) bool

Compares two strings (typical password hashes) in safe mode with constant time. Returns true if they are equal.

Types

type Scheme

type Scheme interface {
	// Hash hashes a plaintext UTF-8 password using a modular crypt stub.
	// Returns the hashed password in modular crypt format.
	//
	// The modular crypt stub is a hash prefix in modular crypt format,
	// which expresses all necessary configuration information,
	// such as salt and iterations.
	// Example of a stub for sha256-crypt:
	//     $5$rounds=6000$salt
	//
	// A full modular crypt hash can also be passed as the stub,
	// in which case the hash is ignored.
	Hash(password string) (string, error)

	// Verify verifies a password in UTF-8 format using a modular crypt hash.
	// Returns an error if the input data are malformed or the password does not match.
	Verify(password, hash string) (err error)

	// SupportsStub returns true if this crypter supports the given stub.
	SupportsStub(stub string) bool

	// NeedsUpdate returns true if this stub needs an update.
	NeedsUpdate(stub string) bool
}

The Scheme interface provides an abstract interface for implementing a particular password hashing scheme. The Scheme generates password hashes, verifies passwords using hashes, randomly generates new stubs and can determine if it recognizes a given stub or hash. It can also decide to issue upgrades.

Jump to

Keyboard shortcuts

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