password

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package password contains password hashing + verification functionality. TLDR; "just use bcrypt".

bcrypt is salting the password as part of hashing. If you're sure you want to pepper, do it to the password prior to passing here.

Index

Constants

View Source
const (

	// Max password length in bytes. bcrypt only takes into account 72 bytes, and will error if given more.
	MaxPasswordLen = 72
)

Variables

View Source
var ErrPasswordEmpty = errors.New("password is empty")
View Source
var ErrPasswordTooLong = errors.New("password length exceeds 72 bytes")

Functions

func Hash

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

Hash applies a salt to the given password and returns the hash. This will return ErrPasswordTooLong if the password is longer than MaxPasswordLen, and ErrPasswordEmpty if the password is empty.

func IsValid

func IsValid(hash []byte, givenPass string) bool

IsValid returns true if the hashed password equals the given hash. Checks against unreasonable length passwords are expected to be done before calling this. For backwards compatibility, this will not error if the given password is too long, and only operates on the first 72 bytes of givenPass.

Types

This section is empty.

Jump to

Keyboard shortcuts

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