All packages

    golang.org/x/crypto/bcrypt

    import "golang.org/x/crypto/bcrypt"

    Package bcrypt implements Provos and Mazières's bcrypt adaptive hashing algorithm. See http://www.usenix.org/event/usenix99/provos/provos.pdf

    Go 1.26.1

    Constants

    const (
    	MinCost     int = 4  // the minimum allowable cost as passed in to GenerateFromPassword
    	MaxCost     int = 31 // the maximum allowable cost as passed in to GenerateFromPassword
    	DefaultCos...

    golang.org/x/crypto/bcrypt/bcrypt.go:24

    const (
    	MinCost     int = 4  // the minimum allowable cost as passed in to GenerateFromPassword
    	MaxCost     int = 31 // the maximum allowable cost as passed in to GenerateFromPassword
    	DefaultCos...

    golang.org/x/crypto/bcrypt/bcrypt.go:23

    const (
    	MinCost     int = 4  // the minimum allowable cost as passed in to GenerateFromPassword
    	MaxCost     int = 31 // the maximum allowable cost as passed in to GenerateFromPassword
    	DefaultCos...

    golang.org/x/crypto/bcrypt/bcrypt.go:22

    Variables

    var ErrHashTooShort = errors.New("crypto/bcrypt: hashedSecret too short to be a bcrypted password")

    The error returned from CompareHashAndPassword when a hash is too short to be a bcrypt hash.

    golang.org/x/crypto/bcrypt/bcrypt.go:33

    var ErrMismatchedHashAndPassword = errors.New("crypto/bcrypt: hashedPassword is not the hash of the given password")

    The error returned from CompareHashAndPassword when a password and hash do not match.

    golang.org/x/crypto/bcrypt/bcrypt.go:29

    var ErrPasswordTooLong = errors.New("bcrypt: password length exceeds 72 bytes")

    ErrPasswordTooLong is returned when the password passed to GenerateFromPassword is too long (i.e. > 72 bytes).

    golang.org/x/crypto/bcrypt/bcrypt.go:87

    Functions

    func CompareHashAndPassword(hashedPassword []byte, password []byte) error

    CompareHashAndPassword compares a bcrypt hashed password with its possible plaintext equivalent. Returns nil on success, or an error on failure.

    golang.org/x/crypto/bcrypt/bcrypt.go:108

    func Cost(hashedPassword []byte) (int, error)

    Cost returns the hashing cost used to create the given hashed password. When, in the future, the hashing cost of a password system needs to be increased in order to adjust for greater computational power, this function allows one to establish which passwords need to be updated.

    golang.org/x/crypto/bcrypt/bcrypt.go:131

    func GenerateFromPassword(password []byte, cost int) ([]byte, error)

    GenerateFromPassword returns the bcrypt hash of the password at the given cost. If the cost given is less than MinCost, the cost will be set to DefaultCost, instead. Use CompareHashAndPassword, as defined in this package, to compare the returned hashed password with its cleartext version. GenerateFromPassword does not accept passwords longer than 72 bytes, which is the longest password bcrypt will operate on.

    golang.org/x/crypto/bcrypt/bcrypt.go:95

    Types

    type HashVersionTooNewError byte

    The error returned from CompareHashAndPassword when a hash was created with a bcrypt algorithm newer than this implementation.

    golang.org/x/crypto/bcrypt/bcrypt.go:37

    func (hv HashVersionTooNewError) Error() string

    golang.org/x/crypto/bcrypt/bcrypt.go:39

    type InvalidCostError int

    golang.org/x/crypto/bcrypt/bcrypt.go:50

    func (ic InvalidCostError) Error() string

    golang.org/x/crypto/bcrypt/bcrypt.go:52

    type InvalidHashPrefixError byte

    The error returned from CompareHashAndPassword when a hash starts with something other than '$'

    golang.org/x/crypto/bcrypt/bcrypt.go:44

    func (ih InvalidHashPrefixError) Error() string

    golang.org/x/crypto/bcrypt/bcrypt.go:46