passwd

package
v0.20.8 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Password policy (NIST SP 800-63B shape: a length floor, a generous
	// ceiling, no composition rules)
	MinPasswordLength = 8
	MaxPasswordLength = 128
)

Password hashing for builtin user accounts. Hashes are stored as PHC strings so the algorithm and its parameters are self-describing: new hashes are argon2id with the OWASP recommended minimum parameters, bcrypt hashes ($2a$/$2b$/$2y$, produced by older versions and by `openrun password`) are still verified. A caller which verified a password against a hash NeedsRehash reports as outdated can store HashPassword of the same password to upgrade it in place.

View Source
const (
	PASSWORD_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#%^&*()_-+=<>?/|"
	BCRYPT_COST    = 10
)

Variables

View Source
var ErrPasswordHashFormat = errors.New("unsupported password hash format")

Functions

func DummyHash added in v0.20.6

func DummyHash() string

DummyHash returns a fixed argon2id hash of a random secret, used to run a verification of the same cost for an unknown username so response timing does not reveal whether an account exists

func GeneratePassword

func GeneratePassword() (string, error)

GeneratePassword generates a random password

func GenerateRandString added in v0.18.6

func GenerateRandString(length int, charsAllowed string) (string, error)

GenerateRandString generates a random string of the given length using crypto/rand, with each character drawn from charsAllowed

func GenerateRandomKey added in v0.15.3

func GenerateRandomKey(length int) ([]byte, error)

func GenerateSessionNonce added in v0.15.3

func GenerateSessionNonce() (string, string, error)

func HashPassword added in v0.20.6

func HashPassword(password string) (string, error)

HashPassword returns the argon2id PHC hash of the password, with a fresh random salt: $argon2id$v=19$m=19456,t=2,p=1$<salt>$<hash>

func IsBcryptHash added in v0.20.6

func IsBcryptHash(hash string) bool

IsBcryptHash reports whether the value has a bcrypt prefix

func IsPasswordHash added in v0.20.6

func IsPasswordHash(hash string) bool

IsPasswordHash reports whether the value is a hash VerifyPassword can check

func NeedsRehash added in v0.20.6

func NeedsRehash(hash string) bool

NeedsRehash reports whether a stored hash should be replaced by HashPassword of the same password: bcrypt, or argon2id with parameters other than the current defaults

func ValidatePassword added in v0.20.6

func ValidatePassword(password, username string) error

ValidatePassword enforces the password policy for a builtin user

func VerifyPassword added in v0.20.6

func VerifyPassword(hash, password string) (bool, error)

VerifyPassword checks the password against a stored hash (argon2id PHC or bcrypt). A wrong password returns false with a nil error; an unparseable hash returns an error

Types

This section is empty.

Jump to

Keyboard shortcuts

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