Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrPwdIter = errors.New("iterations is set to negatice number") ErrComparePwd = errors.New("incorrect password") )
Global package-level configuration object. This will be set via SetPwdConfig and used throughout the package.
Functions ¶
func ComparePassword ¶
ComparePassword securely verifies whether the provided plain-text password matches the previously hashed password using the original salt.
Parameters: - currentPwd: The user-supplied password input (plain-text, as []byte). - hashedPwd: The stored hashed password to compare against. - salt: The original salt used during hashing (must match the salt used to generate `hashedPwd`).
Returns: - nil if the password is correct (matches the hash). - ErrComparePwd if the password is incorrect. - Any error returned by the hashing process.
func GeneratePasswordWithAutoSalt ¶
GeneratePasswordWithAutoSalt hashes a password using PBKDF2 with a randomly generated salt. It returns the derived key (hashed password), the generated salt, and an error if any occurs.
The function uses configurations from a global `config` object which should include: - Iter: Number of PBKDF2 iterations - SaltLen: Desired salt length - Hash: Hash function to use (defaults to SHA-256 if not set) - KeyLen: Desired length of the derived key
func GeneratePasswordWithSalt ¶
GeneratePasswordWithSalt securely hashes a password using PBKDF2 with a user-provided salt. It uses the global `config` for parameters like iteration count, key length, and hash function.
Parameters: - password: The plain-text password in byte slice form. - salt: A cryptographically secure salt (must be consistent for password verification).
Returns: - The derived key (hashed password) as a byte slice. - An error if the hashing process fails or configuration is invalid.
func SetPwdConfig ¶
SetPwdConfig initializes or updates the global password hashing configuration.
Parameters: - h: Hash function name as a string ("SHA256", "SHA512"). - itr: Number of iterations for PBKDF2. - keyLen: Desired length of the derived key in bytes. - sLen: Salt length in bytes.
It sets default hash function to SHA-256 if an unknown hash type is provided.
Types ¶
This section is empty.