Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckPasswordHash ¶
CheckPasswordHash compares a plain text password with a bcrypt hash. It returns true if the password matches the hash, false otherwise.
Parameters:
- password: The plain text password to verify
- hash: The bcrypt hash to compare against
Returns:
- bool: true if password matches, false otherwise
- error: nil if comparison succeeded (even if password doesn't match), error only for unexpected failures (e.g., corrupted hash)
Example:
valid, err := security.CheckPasswordHash("myPassword123", hashedPassword)
if err != nil {
log.Fatal(err)
}
if !valid {
fmt.Println("Invalid password")
}
func HashPassword ¶
HashPassword hashes a password using bcrypt with the default cost factor. It returns the bcrypt hash as a string, or an empty string if hashing fails.
Parameters:
- password: The plain text password to hash
Returns:
- string: The bcrypt hash (60 characters), or empty string on error
Example:
hash := security.HashPassword("myPassword123")
if hash == "" {
log.Fatal("Failed to hash password")
}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.