crypto

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPasswordHash = errors.New("crypto: invalid password hash")

ErrInvalidPasswordHash is returned by VerifyPassword when the stored PHC string cannot be parsed. Callers should treat this as a server-side fault, not a credential mismatch.

Functions

func HashPassword added in v0.2.0

func HashPassword(plain string) (string, error)

HashPassword returns an argon2id PHC-formatted hash of the plain password. Format:

$argon2id$v=19$m=<KiB>,t=<iters>,p=<threads>$<base64(salt)>$<base64(hash)>

Salt is freshly random per call — two hashes of the same password differ.

func HashToken

func HashToken(token string) []byte

HashToken returns sha256(token) as raw bytes — store this, never the token itself.

func NewToken

func NewToken() (string, error)

NewToken returns a 32-byte cryptographically random token, URL-safe-base64-encoded.

func VerifyPassword added in v0.2.0

func VerifyPassword(plain, phc string) (bool, error)

VerifyPassword parses the PHC string and constant-time-compares the supplied plain password against it. Returns (true, nil) on match, (false, nil) on mismatch, and (false, ErrInvalidPasswordHash) on a malformed hash.

Types

This section is empty.

Jump to

Keyboard shortcuts

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