password

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPasswordHashArgon2

func CheckPasswordHashArgon2(encoded, password string) (bool, error)

CheckPasswordHashArgon2 verifies if a given plain password matches the Base58-encoded hash. Returns true if they match, false otherwise.

func CheckPasswordHashBcrypt

func CheckPasswordHashBcrypt(password, hash string) bool

CheckPasswordHashBcrypt compares a bcrypt hashed password with its possible plain text equivalent. Returns true if the password matches the hash, false otherwise.

Example:

match := CheckPasswordHashBcrypt("mySecret123", storedHash)

func HashPasswordArgon2

func HashPasswordArgon2(password string, p *Params) (string, error)

HashPasswordArgon2 generates a secure, encoded Argon2ID hash string using Base58. It marshals the hash, salt, and params into a JSON structure and encodes it. Returns a Base58 encoded string safe to store in databases or configuration.

func HashPasswordBcrypt

func HashPasswordBcrypt(password string) (string, error)

HashPasswordBcrypt hashes the given plain text password using the bcrypt algorithm. It returns the hashed password as a string and any error encountered during hashing.

Example:

hash, err := HashPasswordBcrypt("mySecret123")
if err != nil { ... }

Types

type Hash

type Hash struct {
	Data   []byte  `json:"data"`
	Salt   []byte  `json:"salt"`
	Params *Params `json:"params"`
}

Hash represents the encoded structure used to store a hashed password, including the derived hash, salt, and the parameters used.

type Params

type Params struct {
	Memory      uint32 `json:"m"` // Memory in KB
	Iterations  uint32 `json:"i"` // Number of iterations
	Parallelism uint8  `json:"p"` // Number of parallel threads
	SaltLength  uint32 `json:"s"` // Length of the random salt
	KeyLength   uint32 `json:"k"` // Desired length of the resulting key
}

Params holds configuration for the Argon2ID hash function. It includes memory usage, number of iterations, parallelism, salt length, and resulting key length.

Jump to

Keyboard shortcuts

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