password

package
v3.1.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package password exposes Nauthilus-compatible password comparison and full password-hash helpers for native Go plugins without importing server internals.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedAlgorithm is returned for password hash algorithms outside the public helper contract.
	ErrUnsupportedAlgorithm = errors.New("unsupported hash algorithm")

	// ErrUnsupportedEncoding is returned for password hash payload encodings outside the public helper contract.
	ErrUnsupportedEncoding = errors.New("unsupported password encoding")
)

Functions

func CompareHash

func CompareHash(hashPassword string, plainPassword pluginapi.Secret) (bool, error)

CompareHash verifies a public plugin secret against a stored Nauthilus-compatible password hash.

func CompareHashBytes

func CompareHashBytes(hashPassword string, plainPassword []byte) (bool, error)

CompareHashBytes verifies plain password bytes against a stored Nauthilus-compatible password hash.

func CompareHashString

func CompareHashString(hashPassword string, plainPassword string) (bool, error)

CompareHashString verifies a plain-text string against a stored Nauthilus-compatible password hash.

func FullHash

func FullHash(value []byte) string

FullHash returns the lowercase full SHA-256 digest of prepared bytes.

func GenerateHash

func GenerateHash(secret pluginapi.Secret, options HashOptions) (string, error)

GenerateHash creates the Nauthilus full password hash for a public plugin secret.

func GenerateHashBytes

func GenerateHashBytes(password []byte, options HashOptions) string

GenerateHashBytes creates the Nauthilus full hash for plain password bytes.

func GenerateHashString

func GenerateHashString(password string, options HashOptions) string

GenerateHashString creates the Nauthilus full hash for a plain-text password string.

func PrepareBytes

func PrepareBytes(password []byte, nonce []byte) []byte

PrepareBytes applies the Nauthilus password nonce layout before hashing.

Types

type Algorithm

type Algorithm uint8

Algorithm identifies supported salted SHA password hash algorithms.

const (
	// AlgorithmUnknown represents an unsupported password hash algorithm.
	AlgorithmUnknown Algorithm = iota

	// AlgorithmSSHA256 identifies salted SHA-256 password hashes.
	AlgorithmSSHA256

	// AlgorithmSSHA512 identifies salted SHA-512 password hashes.
	AlgorithmSSHA512
)

type CryptPassword

type CryptPassword struct {
	Salt      []byte
	Password  string
	Algorithm Algorithm
	Encoding  Encoding
}

CryptPassword stores parsed or generated salted SHA password material.

func (*CryptPassword) GenerateBytes

func (c *CryptPassword) GenerateBytes(plainPassword []byte, salt []byte, algorithm Algorithm, encoding Encoding) (string, error)

GenerateBytes creates a salted SHA payload from plain password bytes.

func (*CryptPassword) GenerateString

func (c *CryptPassword) GenerateString(plainPassword string, salt []byte, algorithm Algorithm, encoding Encoding) (string, error)

GenerateString creates a salted SHA payload from a plain-text password string.

func (*CryptPassword) GetParameters

func (c *CryptPassword) GetParameters(cryptedPassword string) (salt []byte, algorithm Algorithm, encoding Encoding, err error)

GetParameters parses a salted SHA password hash and records the payload metadata.

type Encoding

type Encoding uint8

Encoding identifies the payload encoding used by salted SHA password hashes.

const (
	// EncodingUnknown represents an unsupported password payload encoding.
	EncodingUnknown Encoding = iota

	// EncodingBase64 stores the hash+salt payload with base64 encoding.
	EncodingBase64

	// EncodingHex stores the hash+salt payload with hexadecimal encoding.
	EncodingHex
)

type HashOptions

type HashOptions struct {
	Nonce []byte
	// DevMode is retained for source compatibility and no longer changes hash output.
	DevMode bool
}

HashOptions controls generated password hashes.

Jump to

Keyboard shortcuts

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